Support » Plugin: Ajax Search Lite » Show only parent posts of custom post type

  • Resolved Jayanta

    (@jkmwp)


    Hello, I wish that ASL only searches parent posts of the custom post type ‘eng_topic’ on our site. How to make that happen? currently it’s showing all posts of that post type in search result.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi,

    I’m not sure if this is possible to do, maybe via custom coding, but even then it is not 100% doable – as a parent post can be a child post as well.

    Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    add_filter( 'asl_query_args', 'asl_query_args_results_parents_only', 10, 1 );
    function asl_query_args_results_parents_only( $args ) {
    	$args['post_parent'] = array_merge($args['post_parent'], array(0));
    	return $args;
    }

    Best,
    Ernest M.

    Thread Starter Jayanta

    (@jkmwp)

    Thanks so much Ernest. I confirm your above snippet worked.

    Plugin Author wpdreams

    (@wpdreams)

    That is great 🙂

    I will mark this as resolved then.

    Feel free to rate the plugin if you like it, it is greatly appreciated.

    Best,
    Ernest M.

    Thread Starter Jayanta

    (@jkmwp)

    Already rated. Thanks.

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