PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.2
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / class-lp-query-search.php

class-lp-query-search.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7.2, at inc/class-lp-query-search.php

108 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class LP_Query_Search
5 *
6 * @depecated 4.1.6.6
7 */
8 class LP_Query_Search {
9 /**
10 * Search posts.
11 *
12 * @param mixed $args
13 *
14 * @return mixed
15 */
16 public static function search_items( $args = '' ) {
17 global $wpdb;
18
19 $args = wp_parse_args(
20 $args,
21 array(
22 'term' => '',
23 'type' => '',
24 'context' => '',
25 'context_id' => 0,
26 'include' => '',
27 'exclude' => '',
28 'fields' => array(),
29 'limit' => - 1,
30 'paged' => 0,
31 )
32 );
33
34 $user = learn_press_get_current_user();
35 $term = $args['term'];
36 $type = $args['type'];
37 $context = $args['context'];
38 $context_id = absint( $args['context_id'] );
39 $include = array();
40 $exclude = array();
41 $authors = array();
42
43 if ( ! empty( $args['exclude'] ) ) {
44 if ( is_string( $args['exclude'] ) ) {
45 $args['exclude'] = explode( ',', $args['exclude'] );
46 }
47 $exclude = array_map( 'intval', $args['exclude'] );
48 }
49
50 if ( ! empty( $args['include'] ) ) {
51 if ( is_string( $args['include'] ) ) {
52 $args['eincludexclude'] = explode( ',', $args['include'] );
53 }
54 $include = array_map( 'intval', $args['include'] );
55 }
56
57 $exclude = apply_filters( 'learn-press/search-items/exclude', $exclude, $type, $context, $context_id );
58 $include = apply_filters( 'learn-press/search-items/include', $include, $type, $context, $context_id );
59
60 if ( ! $user->is_admin() ) {
61 $authors[] = $user->get_id();
62 }
63
64 if ( $context && $context_id ) {
65 if ( get_post_type( $context_id ) == $context ) {
66 $post_author = get_post_field( 'post_author', $context_id );
67 $authors[] = $post_author;
68
69 if ( $post_author != $user->get_id() ) {
70 $authors[] = $user->get_id();
71 }
72 }
73 }
74
75 $query_args = array(
76 'post_type' => array( $type ),
77 'posts_per_page' => $args['limit'],
78 'post_status' => 'publish',
79 'order' => 'ASC',
80 'orderby' => 'parent title',
81 'post__not_in' => $exclude,
82 'include' => $include,
83 'author' => $authors,
84 );
85
86 if ( $term ) {
87 $query_args['s'] = $term;
88 }
89
90 if ( $args['paged'] ) {
91 $query_args['offset'] = ( $args['paged'] - 1 ) * $args['limit'];
92 }
93
94 $query_args = apply_filters( 'learn-press/search-items/args', $query_args, $type, $context, $context_id );
95
96 global $wp_query, $wpdb;
97
98 $posts = get_posts( $query_args );
99 $q = new WP_Query( $query_args );
100
101 return array(
102 'items' => $posts,
103 'total' => $q->found_posts,
104 'pages' => $q->max_num_pages,
105 );
106 }
107 }
108