Exclude categories from Loop, queries, widgets, post navigation

Excluding categories with pre_get_posts() I found that excluding a category via pre_get_posts() and set_query_var() would work fine except for widgets. The Recent Post Widget would only exclude the category when using $query->set() instead. <?php /** * Does NOT apply to the Recent Posts widget. */ function glck1403271109_exclude_categories( $query ) { $excluded = array( ‘1’, ‘2’ … Read more

Skipping first 3 posts in wp query

For skipping the post just use offset parameter in wp_query. To display latest three post : <?php $latestpost = new WP_Query(‘order=asc&orderby=meta_value&meta_key=date&posts_per_page=3’); //Here add loop to display posts like while($latestpost->have_posts()) : $latestpost->the_post(); the_title(); the_content(); endwhile; wp_reset_query(); //After that skip three posts using offset $latestpost = new WP_Query(‘order=asc&orderby=meta_value&meta_key=date&posts_per_page=6&offset=3&paged=’ . $paged); the_title(); the_content(); endwhile; wp_reset_query(); ?> That’s it

Exclude the category from the WordPress loop

you could use wp_parse_args() to merge your arguments into the default query // Define the default query args global $wp_query; $defaults = $wp_query->query_vars; // Your custom args $args = array(‘cat’=>-4); // merge the default with your custom args $args = wp_parse_args( $args, $defaults ); // query posts based on merged arguments query_posts($args); although, i think … Read more

Exclude Specific Term from Search

The basic explanation You have a template tag that is called is_search() to determin if you’re on a search page or not. This then calls get_search_template() which basically is a wrapper function for get_query_template(‘search’). When you look into the last function, then you’ll see that it basically does locate_template(), which checks for file existence and … Read more

How do I exclude plugins from getting automatically updated?

Instead of using the code from the question in functions.php, replace it with this: /** * Prevent certain plugins from receiving automatic updates, and auto-update the rest. * * To auto-update certain plugins and exclude the rest, simply remove the “!” operator * from the function. * * Also, by using the ‘auto_update_theme’ or ‘auto_update_core’ … Read more

Dynamically exclude menu items from wp_nav_menu

Method 1 You can add a constructor to your custom Walker to store some additional exclusion arguments, like: class custom_nav_walker extends Walker_Nav_Menu { function __construct( $exclude = null ) { $this->exclude = $exclude; } function skip( $item ) { return in_array($item->ID, (array)$this->exclude); // or return in_array($item->title, (array)$this->exclude); // etc. } // …inside start_el, end_el if … Read more