Join our new community forum for support & discussion

Join Now

Home Support Themes TaskHive how to exclude listings

how to exclude listings

  • Author
    Posts
  • joelblack

    Ive had to create some duplicate listings to be able to sell both one time task and recurring monthly task. The problem is it creates 2 listings in the feed of listings. How can I exclude listings from the feed of listings? I will need to exclude the monthly duplicate listings on a regular basis.

    https://findhelp.socialmediaexaminer.com/services/

    yevhen developer

    It is possible, but requires customizing the listing query. If these duplicate listings have any extra field or option that allows filtering them then it may be possible to exclude these listings from the search and category pages via this hook https://developer.wordpress.org/reference/hooks/pre_get_posts/

    joelblack

    I added a checkbox that is called “Monthly”, and it is these monthly listings that I do not want showing in the listing query. So the name of the checkbox (best I can tell by inspecting element) looks to be “hp_hidden” and if it is monthly is will be a value of 1.

    So how would I hook into that to exclude hp_hidden = 1

    https://nimb.ws/SlO7rt

    yevhen developer

    Sorry, there is no simple code snippet for this. If you are familiar with customizations or have a developer for custom work please try using the pre_get_posts hook, to check if it is the main listing query (listing archive, page, or category/search page) there, and add a new meta_query parameter to filter listings by the hp_hidden meta key and 1 value. Hope this helps.

    joelblack

    I can not get this to work. Do you see anything wrong with this? It removed all post

    joelblack
    function target_main_category_query_with_conditional_tags( $query ) {
        if ( $query->is_main_query() && ! is_admin() ) {
    		$meta_query = array(
    			array(
    				'key' => 'hp_hidden',
    				'value' => '1',
    				'compare' => '!='
    			)
    		);
    		$query->set( 'meta_query', $meta_query );
    	}
    }
    add_action( 'pre_get_posts', 'target_main_category_query_with_conditional_tags' );
    joelblack

    So I got the below working in the WordPress admin, category page, search results, but it will not work on the main listing page results. Any idea why it would not work on the main queery? Are you using a different query on that other than is_main_query() ?

    function exclude_posts_from_search( $query ){
       if($query->is_main_query() ){
         $query->set('meta_query', array(array("key"=>"hp_hidden", "compare"=>"NOT EXISTS")));
       }
    }
    
    add_action('pre_get_posts','exclude_posts_from_search');
    yevhen developer

    Sorry, unfortunately there is no simple code snippet for this, this requires some research and customizations. For customizing the search query only, you can try this hook https://hivepress.github.io/hook-reference/hivepress_v1_models_%257Bmodel_name%257D_search.html Use listing as a model name. Please consider hiring someone with WordPress customizations experience via Fiverr or Upwork for assistance.

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

New Reply

This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.