Support » Developing with WordPress » how to get user post by their id and add it to search arguments meta query

  • i have create a function to get user id
    here i want to get user post by provided user id and add related search arguments to meta query but my code does not work can anyone help

    // advertiser
    if( !function_exists( 'advertiser_search' ) ) :
    * Add advertiser related search arguments to meta query
    * @param $meta_query
    * @return array
    function advertiser_search( $meta_query ) {
    if ( isset( $_GET[ 'advertisers' ] ) && ! empty( $_GET[ 'advertisers' ] ) ) { // advertisers = user_id
    $meta_query[] = array(
    'value' => $_GET[ 'advertisers' ], // advertisers = user_id
    'compare' => 'IN',
    return $meta_query;
    add_filter( 'project_meta_search', 'advertiser_search' );
    • This topic was modified 2 weeks, 3 days ago by  Jan Dembowski. Reason: Fixed code
Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    I don’t know what the “project_meta_search” filter does with the returned value, I’m assuming it uses it as a “meta_query” argument for a WP_Query object. If that’s the case, meta_query array structure is an array of arrays, so you probably just need to add another array level.

    $meta_query[] = array( array(
    'value' => $_GET[ 'advertisers' ], // advertisers = user_id
    'compare' => 'IN',

    This may seem odd because you only are supplying one criteria. Meta queries can be much more complex. We need that extra layer so other argument arrays can be combined in the one overall argument array.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.