Tag Info

Hot answers tagged

11

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. * * This function could easily be altered to do the opposite, by auto-updating specific * plugins and excluding the rest. * * Also, by using the 'auto_update_theme' 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 ( ! ...


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

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

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


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


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

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

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

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


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

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

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

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

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

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

$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

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

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

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


1

Based on Johannes’ code, but using the post__not_in argument: /* Secondary query using WP_Query */ $wpse63027_posts = new WP_Query( array( 'category_name' => 'MyCatName', 'posts_per_page' => -1, 'post__not_in' => array( get_queried_object_id() ), // Exclude current post ID (works outside the loop) ) ); Then you can loop through the ...


1

First, do not use query_posts() for secondary loops. The query_posts() function is intended only to modify the primary loop query. Use WP_Query() or get_posts() for secondary loop queries. Also, showposts is deprecated. Use posts_per_page instead. Let's use WP_Query(), as it will be the most analogous to your current implementation: <?php // First, ...


1

This one is even more simple. Refer to the WP_Query() category parameters. I think you will want to use 'category__not_in'. foreach ( $random_posts_cat_array as $random_post_cat ) { if ( $post_cat_slug == $random_post_cat ) { // No posts from this category! $random_posts_query_args['category__not_in'] = $post_cat_id; } } Edit ...


1

I'm not entirely clear on what you are trying to do exactly because "I had to manually build another menu. I just created a list and inserted links to the pages I needed, without using any WordPress function." didn't make a whole lot of sense. You need to exclude pages by including the exclude parameter within your wp_list_pages function. E.g. (example: ...


1

You say "regardless of the params I use"... You're not using the include at the same time, are you? Troubleshooting ideas: use only [gallery exclude="93"] remove it from the Featured Image put the shortcode in the post content


1

Don't change your template, and please do not use query_posts. Add this to your function.php: add_action('pre_get_posts', 'filter_out_children'); function filter_out_children( $query ) { if ( is_main_query() && is_category() && ! is_admin() ) { $qo = $query->get_queried_object(); $tax_query = array( 'taxonomy' => ...



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