How to show only specific category post by user role without plugin and restrict all other cats

If you’re using global loop for displaying the posts, then you can easily modify which posts are shown using pre_get_posts action. function restrict_categories_for_user( $query ) { if ( ! is_admin() && $query->is_main_query() && get_current_user_id() ) { $user = wp_get_current_user(); if ( in_array( ‘viewer_a’, (array) $user->roles ) ) { // The user has the “viewer_a” role … Read more

Scheduled post delete – can’t pass the cron arguments

Comparing your code to the WordPress function wp_schedule_single_event, it appears you failed to indicate that parameters would be passed. Perhaps the following version of your code will work for you. add_action( ‘crondelete’, ‘delete_page_in’,10,1); wp_schedule_single_event($seconds, ‘crondelete’, array($new_post_id )); Notice the add_action now includes two extra parameters: 10=Priority, and 1=Accepted Arguments to be passed.

Limiting WordPress Search function : Custom build

This code will only search form woocommerce products. If you want to show any other search result from another post type you can do by simply change post type slug ‘product’ with you own post type slug add_action( ‘pre_get_posts’, ‘wpse223576_search_woocommerce_only’ ); function wpse223576_search_woocommerce_only( $query ) { if( ! is_admin() && is_search() && $query->is_main_query() ) { … Read more

Parent category as WOOCommerce Categories widget title

Try this it works for me. Place this code in your theme functions.php file. function dynamic_product_category_widget($title, $widet_instance, $widget_id) { if ( $widget_id !== ‘woocommerce_product_categories’ ) return $title; if ( is_product_category() ) { $cat_title = single_cat_title(‘<p class=”widget-title footer-widget”>’, ‘</p>’); return $cat_title; } elseif ( is_product() ) { $cat = get_the_terms( $product->ID, ‘product_cat’ ); foreach ($cat as … Read more