Tag Info

Hot answers tagged

16

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' ...


9

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 ...


7

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 ...


5

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 ...


5

You'll need to filter comments_clauses, since WP_Comment_Query only supports a limited post type == X argument. /** * Exclude comments of the "foobar" post type. * * @param array $clauses * @param object $wp_comment_query * @return array */ function wpse_72210_comments_exclude_post_type( $clauses, $wp_comment_query ) { global $wpdb; if ( ! ...


4

Don't use query_posts. Use a filter on pre_get_posts. function no_front_sticky_wpse_98680($qry) { if (is_front_page()) { $qry->set('post__not_in',get_option( 'sticky_posts' )); } } add_action('pre_get_posts','no_front_sticky_wpse_98680'); By running query_posts you clobber the main query, over-writing it with another query. That is why you ...


4

I have rewritten the query_posts. As for get_posts you are better off using the WP_Query due to more control over the tax_query. Explained here. <?php $args = array( 'cat' => 84, 'posts_per_page' => 3, 'offset' => 0, 'tax_query' => array( 'relation' => 'NOT IN', array( 'taxonomy' => 'display', ...


4

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 ...


3

You just need to set the operator parameter to 'NOT IN' (see Codex on tax queries). Untested, but for your purposes: $args = array( 'post_type'=> 'post', 'post_status' => 'publish', 'order' => 'DESC', 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', ...


3

In your code, if $post_id were, say, 99, this: query_posts("showposts=4&post_type=page&post_parent=168&orderby=rand&exclude='. $post_id .'"); would result in this being passed to query posts: query_posts("showposts=4&post_type=page&post_parent=168&orderby=rand&exclude='. 99 .'"); so, your issue here is '. 99 .' isn't a ...


3

First off, note that, since your custom loop is a secondary loop/query, you should use the WP_Query class instead of query_posts(). Read why. That being said, /* main post's ID, the below line must be inside the main loop */ $exclude = get_the_ID(); /* alternatively to the above, this would work outside the main loop */ global $wp_query; $exclude = ...


3

This the post__not_in arg should work dandy for you: $args = array( 'numberposts' => 5, 'offset' => 0, 'category' => 7, 'post__not_in' => array( $post->ID ) ); $myposts2 = get_posts($args);


3

First, don't use query_posts(). Just get rid of the call entirely. It will break things. Second: I tried adding the following before the query_posts ( function but it does nothing. Callbacks and add_action() calls belong in functions.php, not in the template file. If you've put it directly in home.php, remove it from there, and put it in ...


3

Try this in your functions.php, and change news for whatever you want to be blocked in your site. add_action('wp', 'check_search'); function check_search() { global $wp_query; if (!$s = get_search_query()) return false; if (preg_match('/news/', $s)) { $wp_query->set_404(); status_header(404); ...


3

Rather than performing a separate query, to exclude a category (or any other taxonomy) term, you can hook into pre_get_posts: add_action('pre_get_posts', 'wpse41820_exclude_cat_from_front_page'); function wpse41820_exclude_cat_from_front_page( $query ){ if( $query->is_main_query() && is_front_page() ){ $tax_query = array(array( ...


3

The original author isn't quite right in saying "which is merely the more elegant way to write". set_query_var() will always override the main query, whereas if you actually use: $wp_query->set( 'category__not_in', $excluded ); ... it will work for any instance of query_posts(), such as the recent posts widget.


2

On your argument, exclude the current post using post__not_in $args=array( 'post_type'=>'projects', 'orderby'=>'rand', 'posts_per_page'=>'1', 'post__not_in'=> array( get_the_ID() ) );


2

Your two queries are identical, meaning you only need one of them. The basic solution is: global $testimonials; $testimonials = new WP_Query(array( 'posts_per_page' => 2, /* <-- get both */ 'post_type' => 'testimonial', 'post_status' => 'published', 'orderby' => 'rand', 'ignore_sticky_posts' => true /* you need ...


2

If you don't use any other meta data, just add the following to your $args: 'meta_key' => 'sold', 'meta_value' => true, // or whatever it is you're using here 'meta_compare' => '!=', Otherwise, use a WP_Meta_Query: 'meta_query' => array( array( 'key' => 'sold', 'value' => true, // or whatever it is you're using here ...


2

Looks like you've excluded a taxonomy term, not the whole taxonomy. Is that what you intended? But on to the answer... Right before your query in the widget add: remove_action( 'pre_get_posts', 'exclude_category_posts' ); And then you probably want to put it back again after that query by repeating: add_action( 'pre_get_posts', 'exclude_category_posts' ...


2

Declare the following function in your functions.php function wpse58346_wp_list_pages( $pages, $r ) { foreach( $pages as $key => $page ) { if ( 50 < $page->menu_order ) unset($pages[$key]); } return $pages; } Now before calling wp_list_pages() apply a filter as follows add_filter('get_pages', ...


2

There's a plugin for that :-) http://wordpress.org/extend/plugins/hide-categories/


2

$args = array( 'meta_key' => 'home_post_id', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'meta_query' => array( array( 'key' => 'home_post_id', 'value' => 0, 'compare' => '>', 'type' => 'numeric', ) ) ); query_posts($args); Something ...


2

query_posts will clobber the main query. You've overwritten the original set of posts. Don't use query_posts Instead create a new WP_Query object for your second set of posts, and another Loop. It sounds like what you are trying to do is overly complicated. "Mixing" two queries is not likely to be worth the effort. It appears that you are going to have two ...


2

pre_get_posts is the right hook for this since i just did category exclusion in another answer i will post it here too. Exclude the category from the Wordpress loop based on the codex sample: http://codex.wordpress.org/Custom_Queries#Category_Exclusion add_action('pre_get_posts', 'wpa_31553' ); function wpa_31553( $wp_query ) { //$wp_query is ...


2

Did you consult the is_page_template() Codex entry? If you want to query for the page.php page template, then you need to pass that filename to is_page_template(); i.e.: <?php if ( ! is_page_template( 'page.php' ) ) { // The current page template is NOT page.php; // do something } ?> Sidenote: if you want to query for being a static page ...


2

If everything else is doing what you want, change this line: $categories = get_categories('hide_empty=0'); To this: $categories = get_categories('hide_empty=0&exclude=10'); Swap '10' with the category number you want to exclude.


2

All media (somewhat incorrectly) in the $wpdb->posts table will be "attachments" whether actually attached or not. "Attachments" that are actually attached will have a post_parent other than 0, so what you need are all of the attachments that have a 0 in the post_parent column, if I understand you. $args = array( 'post_type' => 'attachment', ...


2

Note as of wordpress 3.8.2 the type of the plugin item passed to this function has changed and it is now an object. /** * @package Plugin_Filter * @version 2.0 */ /* Plugin Name: Plugin Filter Plugin URI: http://www.brideonline.com.au/ Description: Removes certain plugins from being updated. Author: Ben Wise Version: 2.0 Author URI: ...


2

First, please don't use query_posts() (emphasis mine)! Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the ...



Only top voted, non community-wiki answers of a minimum length are eligible