php - Exclude Products from loop using woocommerce -


I have to exclude some products in the category loop product page using woocommerce. Only that product will be given a specific value in the meta table. I have written the code below but it is not working for me. Please help me.

  add_filter ('pre_get_posts', 'custom_pre_get_posts_query'); Function custom_pre_get_posts_query ($ q) {if (! $ Q- & gt; is_main_query ()) returns; If (! $ Q- & gt; is_post_type_archive ()) returns; $ Q- & gt; Set ('meta_query', array (array (array ('key' = & gt; '_auction_closed', 'compare' = & gt; 'does not exist')))); Remove_filter ('pre_get_posts', 'custom_pre_get_posts_query'); }  

Try the following code:

  Add_filter ('Pre_get_posts', 'custom_pre_get_posts_query'); Function custom_pre_get_posts_query ($ q) {if (! $ Q- & gt; is_main_query ()) returns; If (! $ Q- & gt; is_post_type_archive ()) returns; $ Meta_query = $ q- & gt; Obtain ('meta_query'); $ Meta_query [] = array ('key' = & gt; '_uction_closed', 'compare' => 'not existing',); $ Q- & gt; Set ('meta_query', $ meta_query); Remove_filter ('pre_get_posts', 'custom_pre_get_posts_query'); }  

Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

class - Kivy: how to instantiate a dynamic classes in python -

python - mayavi mapping a discrete colorbar on a surface -