Question_Query::__construct( array|string $args = array() )
Description #
Initialize class.
Parameters #
- $argsarray | string (Optional) Query args. Default value: array()
Source #
File: includes/qaquery.php
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | public function __construct( $args = array () ) { if ( is_front_page() ) { $paged = ap_sanitize_unslash( 'ap_paged' , 'g' , 1 ); } else { $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; } if ( isset( $args [ 'post_parent' ] ) ) { $post_parent = $args [ 'post_parent' ]; } else { $post_parent = ( get_query_var( 'parent' ) ) ? get_query_var( 'parent' ) : false; } if ( ! isset( $args [ 'ap_order_by' ] ) ) { $args [ 'ap_order_by' ] = ap_get_current_list_filters( 'order_by' , 'active' ); } $defaults = array ( 'showposts' => ap_opt( 'question_per_page' ), 'paged' => $paged , 'ap_query' => true, 'ap_order_by' => 'active' , 'ap_question_query' => true, 'post_status' => array ( 'publish' ), 'ap_current_user_ignore' => false, ); $this ->args = wp_parse_args( $args , $defaults ); $this ->args[ 'ap_order_by' ] = sanitize_title( $this ->args[ 'ap_order_by' ] ); /** * This was suggested by https://github.com/nash-ye. */ if ( ! $this ->args[ 'ap_current_user_ignore' ] ) { // Check if user can read private post. if ( ap_user_can_view_private_post() ) { $this ->args[ 'post_status' ][] = 'private_post' ; } // Check if user can read moderate posts. if ( ap_user_can_view_moderate_post() ) { $this ->args[ 'post_status' ][] = 'moderate' ; } // Check if user can read moderate posts. if ( ap_user_can_view_future_post() ) { $this ->args[ 'post_status' ][] = 'future' ; } // Show trash posts to super admin. if ( is_super_admin() ) { $this ->args[ 'post_status' ][] = 'trash' ; } } // Post status to ignore if passed via args. if ( isset( $this ->args[ 'post_status__not_in' ] ) ) { $post_status__not_in = $this ->args[ 'post_status__not_in' ]; // Update the post_status args. $this ->args[ 'post_status' ] = array_diff ( $this ->args[ 'post_status' ], $post_status__not_in ); } // Updated post_status args to have the unique array. $this ->args[ 'post_status' ] = array_unique ( $this ->args[ 'post_status' ] ); // Show only the unpublished post of author. if ( isset( $args [ 'ap_show_unpublished' ] ) && true === $this ->args[ 'ap_show_unpublished' ] ) { $this ->args[ 'ap_current_user_ignore' ] = true; $this ->args[ 'author' ] = get_current_user_id(); $this ->args[ 'post_status' ] = array ( 'moderate' , 'pending' , 'draft' , 'trash' ); } if ( $post_parent ) { $this ->args[ 'post_parent' ] = $post_parent ; } if ( '' !== get_query_var( 'ap_s' ) ) { $this ->args[ 's' ] = ap_sanitize_unslash( 'ap_s' , 'query_var' ); } $this ->args[ 'post_type' ] = 'question' ; parent::__construct( $this ->args ); } |
Expand full source code Collapse full source code View on GitHub: includes/qaquery.php:37
Add your comment