mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/68813561/i-want-to-hide-woocommerce-products-from-shop-page-using-post-ids
16 lines
418 B
Text
16 lines
418 B
Text
add_action( 'pre_get_posts', 'erginous_exclude_id' );
|
|
|
|
function custom_pre_get_posts_query( $q ) {
|
|
|
|
if ( ! $q->is_main_query() ) return;
|
|
if ( ! $q->is_post_type_archive() ) return;
|
|
|
|
if ( ! is_admin() && is_shop() ) {
|
|
|
|
$q->set( 'post__not_in', array(70, 53) ); // Replace 70 and 53 with your products IDs. Separate each ID with a comma.
|
|
|
|
}
|
|
|
|
remove_action( 'pre_get_posts', 'erginous_exclude_id' );
|
|
|
|
}
|