0

In need of some help. I have my search results showing the custom post type with all the ACF fields inside. What I want is the search result to show the ACF singularly with a field name of file_name that is a text field and file field file_pdf. together they would be one result from any given amount of posts from the user. I can't seem to understand the way to code this. I'm currently using relevanssi plugin. I'm struggling with the idea of filtering just those two fields to show in the results.

function wpb_search_filter($query)
{
    global $current_user;
    if ($query->is_search && !is_admin())
        $query->set('author', $current_user->ID);
    // $query->set( 'post_type', array( 'pricing', 'attachment' ) );
    $query->set('meta_query', array(
        'key'       => 'file_pdf',
        'value'     => $query->query['s']
    ));
    return $query;
}
add_filter('pre_get_posts', 'wpb_search_filter');
  • Wouldn't you just change the template for this custom post type in search results? – MikeNGarrett Jun 13 at 16:44
  • At the moment the search only brings up the post as a whole with all fields in one. I wondered if there must be more to my function then just just that. – henry puttick Jun 13 at 23:41
  • Yes, you can use a template for search results to change the content displayed. – MikeNGarrett Jun 14 at 1:40
  • I had a mad 30mins there. I was going around in circles not thinking clearly. All is sorted now – henry puttick Jun 14 at 3:08

Your Answer

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

Browse other questions tagged or ask your own question.