LLMS_Instructor::get_posts( array $args = array(), string $return = 'llms_posts' )

Retrieve instructor’s posts (courses and memberships, mixed)


Parameters Parameters

$args

(array) (Optional) query arguments passed to WP_Query

Default value: array()

$return

(string) (Optional) return format [llms_posts|ids|posts|query]

Default value: 'llms_posts'


Top ↑

Return Return

(mixed)


Top ↑

Source Source

File: includes/models/model.llms.instructor.php

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
public function get_posts( $args = array(), $return = 'llms_posts' ) {
 
    $serialized_id = serialize( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
        array(
            'id' => $this->get_id(),
        )
    );
    $serialized_id = str_replace( array( 'a:1:{', '}' ), '', $serialized_id );
 
    $args = wp_parse_args(
        $args,
        array(
            'post_type'   => array( 'course', 'llms_membership' ),
            'post_status' => 'publish',
            'meta_query'  => array(
                array(
                    'compare' => 'LIKE',
                    'key'     => '_llms_instructors',
                    'value'   => $serialized_id,
                ),
            ),
        )
    );
 
    $query = new WP_Query( $args );
 
    if ( 'llms_posts' === $return ) {
        $ret = array();
        foreach ( $query->posts as $post ) {
            $ret[] = llms_get_post( $post );
        }
        return $ret;
    } elseif ( 'ids' === $return ) {
        return wp_list_pluck( $query->posts, 'ID' );
    } elseif ( 'posts' === $return ) {
        return $query->posts;
    }
 
    // If 'query' === $return.
    return $query;
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
3.13.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.