0

I am trying to filter a custom post type by some custom fields value and if the posts are by author, query for 2 custom field works but author posts doesn't work. Thanks!

add_filter( 'parse_query', 'my_admin_posts_filter' );

function my_admin_posts_filter( $wp_query ) {

if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php?post_type=estate_leads' ) !== false ) {

    if ( !current_user_can( 'level_10' )  ) {

        $current_user = wp_get_current_user();
        $author = $current_user -> ID;

         $wp_query->set(


        'meta_query', array(
        'relation' => 'OR',

    array(
       'key'       => 'leads_status',
           'value' => '-1',

        ),


          array(
               'key' => 'leads_status',
               'compare' => 'NOT EXISTS',
           ),

         array(

             'key' => 'author',
             'value' => $author,
         )


    ));

}
} }
0

The author key/value query won't work. Try modifying the query by moving the query out of the meta query like so:

array(
    'author' => $author,
    'meta_query' => array(
        'relation' => 'OR',
         array(
             'key'       => 'leads_status',
             'value' => '-1',
         ),
         array(
             'key' => 'leads_status',
             'compare' => 'NOT EXISTS',
         )
    )
)
2
  • Got error: Missing argument 2 for WP_Query::set(), called in Apr 8 '15 at 13:58
  • Here is update code works partially doesnt work the last query to get empty custom field. $wp_query->set( 'author', $author, 'meta_query', array( 'relation' => 'OR', array( 'key' => 'leads_status', 'value' => '-1', ), array( 'key' => 'leads_status', 'compare' => 'NOT EXISTS', ), )); Apr 8 '15 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.