Search pages ONLY in parent category

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Search pages ONLY in parent category

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 years, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23456
    habhop
    habhop
    Participant

    Hi,

    Please could you help me setup the search so that I can have only results in a parent category are displayed in the results?

    For example the search box is displayed on the Parent page ‘Synergy’ http://scancert.co.uk/synergy/

    I would like the results displayed from this form to ONLY include child pages under the parent ‘Synergy’ for example: searching 23 would load the results such as http://scancert.co.uk/synergy/03e023/ and http://scancert.co.uk/synergy/23e001/ but not http://scancert.co.uk/lynch/2332/

    If you could please advise me the best way to do this I would be extremely grateful.

    Many Thanks,

    Sam

    #23458
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Sam,

    This might be possible via a custom code. There is a knowledge base on how to get results for specific page parent IDs. If I understand correctly, you have parent/child pages, and you only need the child pages within the results?

    In that case, via a minor modification to the original custom code, this should do the trick:
    (Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!)

    add_filter( 'asp_query_args', 'asp_include_only_parent_ids', 10, 2 );
    function asp_include_only_parent_ids( $args, $id ) {
      /**
       * Enter the post/cpt prent IDs here. The results will be
       * limited to objects with these parent IDs.   
       */     
      $id = get_the_ID();
      
      if ( !empty($id) )
          $args['post_parent'] = array($id);
      
      return $args;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.