Support Forums

Hey there, it looks like you've been redirected from designsandcode.com - as you can see we have a new home - read more

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Including ACF Post Meta in Results

Viewing 8 posts - 1 through 8 (of 8 total)
  • jking
    #127149

    I have a filter set up to find all posts with a relationship to an ACF called “people”, it returns all results with a relationship to a “person” post but I would also like to return the “person” post itself in the search results.

    What is the easiest way to include it in my results?
    I have tried something like this:

    function people_filter( $query_args, $sfid ) {
        if($sfid == 7287)
        {
        	if ($_GET["_sfm_people"] != "") {
          		$query_args['p'] = intval($_GET["_sfm_people"]);
      	}
        }
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'people_filter', 10, 200 );

    But this returns the “person” post only, I would instead like to add it to the already compiled results.

    Trevor Moderator
    #127266

    The best thing to do to start debugging is to echo out to the page, before and after, what the query array is, using <pre> tags and the PHP print_r function. There are examples in this forum if you search for print_r

    jking
    #127340

    Hmm, I’m getting an empty array. My code:

    function people_filter( $query_args, $sfid ) {
        if($sfid == 7287)
        {
          		echo '<pre>',print_r($query_args,true),'</pre>';
        }
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'people_filter', 10, 200 );

    It’s strange because the archive page is displaying results, maybe it’s firing too late?

    jking
    #127343

    It was actually firing too early. Still I can’t seem to add the post to the results.
    Here is my code:

    function people_filter( $query_args, $sfid ) {
       if($sfid == 7287)
        {
        	if ($_GET["_sfm_people"] != "") {
        		array_push($query_args['post__in'], intval($_GET["_sfm_people"]));
        		echo '<pre>',print_r($query_args,true),'</pre>';
      		}
        }
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'people_filter', 20, 2 );

    And here is what the print_r is echoing:

    Array
    (
        [paged] => 1
        [search_filter_id] => 7238
        [search_filter_override] => 
        [posts_per_page] => -1
        [post_status] => Array
            (
                [0] => publish
            )
    
        [meta_query] => Array
            (
            )
    
        [post_type] => Array
            (
                [0] => lesson
                [1] => people
                [2] => video
                [3] => image
                [4] => article
            )
    
        [is_search] => 1
        [post__in] => 
    )
    Trevor Moderator
    #127381

    Can you test what this actually is:

    $_GET["_sfm_people"]

    by echoing it. I wonder if the code isn’t actually going into the condition because the condition fails?

    jking
    #127477

    Yes, it echos correctly. In this case it is “1691” which is the id of the “person” post being queried. The condition is successful, I can echo the $query_args from inside of it.

    Trevor Moderator
    #127494
    This reply has been marked as private.
    jking
    #127504
    This reply has been marked as private.
Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.