function rpf_add_query_var_not_to_show_user_request_product($query) {
$post_type = $query->get( 'post_type' );
if ( ! is_null($post_type) && $post_type == 'product' ) {
$query->set( 'meta_key', '_user_request' );
$query->set( 'meta_value', 'no' );
$query->set( 'meta_compare', '=' ); // default
}
}
add_action( 'pre_get_posts',
'rpf_add_query_var_not_to_show_user_request_product', 100, 1 );
yes, pre_get_posts is heaven! and $query->set(), $query->get() are angels!
Related Posts:
- Possible to filter the posts or categories that XML-RPC users see in their mobile application?
- Filter custom post types in archive
- Filter Posts by current Month
- Is it possible to apply filter to meta key value when querying posts?
- Want to use wp_get_current_user() in query filter
- Excluding posts by meta, and also keeping posts without the meta
- Customising the default wordpress search functionality
- WP_Query filter by custom meta
- List all categories that have results in a query
- Display posts from today and future in Elementor ‘posts widget’
- Having issue with dynamic data within restrict_manage_posts function
- Displaying posts on a page that have been assigned a value in a database
- Filter on the day of the week from timestamp
- Admin view: filter posts by whether they have specific taxonomy attached
- Restrict access to custom post type and filter from every query
- Adding an orderby filter, casting postmeta with multiple keys
- Query Multiple Filters, one with Meta
- How to filter users on admin users page by custom meta field?
- Passing Additional Parameters to add_filter Callable
- How can I add an Author filter to the Media Library?
- Modify WordPress Rest Api Request/Response
- How to add some custom HTML into wordpress admin bar?
- Change upload directory on custom plugin page
- How to use the_excerpt in a filter hook?
- Add wrapper to only youtube videos via embed_oembed_html filter function
- Hook into admin post list page
- Add post/page ID to inserted links within the_content
- How to exclude/filter a tag from get_the_tag_list()
- Shortcodes not resolved in AJAX call response
- Ajax, filters and shortcodes
- Filter the blog’s title without using global variables
- wp_link_pages output appears twice
- Multiple Ajax Data Action
- Changing a WordPress core function without hacking core
- Change WordPress RSS link with filter?
- How to remove get_post_metadata using remove_filter inside a class?
- where to apply “apply filters” and other Sanitization Functions
- Add guid filter to attachment in media library grid mode
- Sorting and limitation with pre_get_posts
- Warning: Missing argument 2 for widget_title filter
- Use add_filter on concatenated string variable
- Change term name only on front
- How do I hide the current page’s title?
- Change name of existing post status type
- add_filter(‘the_content’, ‘…’) stops pagination from working
- Header image automatically changes depending on season
- How to remove SKU’s from ALL products in Quick View – already remove from each product page
- Admin Backend – Search Pages only by title
- How to hide Ads in between posts on AMP? [closed]
- What is the downside of using a filter as a “poor man’s” dependency injection?
- BBPress changing default group activity
- How can I change the language of automated Mails?
- Filter the_content to add something before each element?
- Replacing a deprecated filter ‘woocommerce_get_price’ with ‘woocommerce_product_get_price’
- How do you get specific tags from the_content?
- Overriding default calendar to show posts from a category
- Filter by category and city for doctors and hospitals in wordpress
- Prevent reset password specific user role
- Why is overwriting $GLOBALS killing the_content()?
- Sorting products by price ( regular + sale price )
- Create new custom field that calculates age
- Remove comments validation (remove filter?)
- How to query if meta_key does exist or not?
- Remove Site Name from wp_title WITHOUT removing from attribute
- Plugin default settings hook
- Usage of filters
- add_filter to the_content after apply_filters
- Where exactly does the edit_{taxonomy} hook fire?
- How to filter with dropdown in backend for custom data
- Is there any reason for the nested filters to be applied on the first case and not in the second one?
- Best practice: Custom Post Type / Filter / Load more
- How to Edit Ecommerce filters URL, h1, h2 , Title
- Redirect an archive page to its relevant URL-friendly filtered page
- Show uploaded pdf files dynamically and filter by month name
- how to use substr with get_the_content()
- AJAX Post Filter
- Mystery line break
- Add filter return false not working
- How to add markup to the wp-custom-header div
- How to take shortcode and content separately from a page?
- Display post after choice two taxonomy terms
- How to stop echoing gallery inside content?
- how to filter datalist table of wordpress
- Ajax Filtering Pagination
- Custom permalink for attachment
- Cutting off excerpt with first sentence
- Change URLs in default WordPress slider to relative from absolute
- Print url to default featured image
- What action/filter can be used for modifying the page to be rendered?
- Fetch only categorized posts
- Adding user filter – Not updating data in URL
- How to add more than one custom metadata as filter on the post list page?
- filter wptexturize doesn’t work on old posts titles
- remove_action conditionally for Custom Post Type – not working
- wp_get_attachment_link filter not working
- Getting entry ID from frm_email_message filter in formidable
- Is there a hook or filter that adds a button to the left of the search box?
- filter a list by gender
- Better way to change the default password reset url with the woocommerce one?
- woocommerce_coupon_is_valid_for_product not working to exclude specific product tag