wordpress custom post listing

October 19, 2009 by jerome

global $wp_query;
query_posts(
	array_merge(
		array('cat' => -420),
		$wp_query->query
	)
);

* while working on a few new Sangbleu pages, i came across this neat way of handling custom query; i found it on the WordPress Codex: query_posts.

What it is essentially doing here is an exclude of all the post of a specific category without affecting the main loop/query generated by the core system of redirects; in other words: it respects the original paging. I found it quite clean and neat – and thought i would share…

** Even after a few months working intensively with WordPress almost like a framework, i’m still able to improve my own tricks and discover new stuff; version 2.9 is around the corner and i’m getting excited a bit with the fusion of the core WP and the MU

*** We are searching for a way to share internally/externally small bits of code, functions, etc (not only WP related) – considering any software repository (wiki, wp, …), what would you recommend?


2 Comments »

  1. if you want to exclude a few more categories you can use something like:

    array_merge(
    array(‘cat’ => -420), array(‘cat’ => -279),
    $wp_query->query
    )

    array_merge accepts many arrays as parameters to be merged. See: http://php.net/manual/en/function.array-merge.php

    Comment by Heb — October 20, 2009 @ 11:30 pm

  2. hey thanks!

    Comment by jerome — October 20, 2009 @ 11:31 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment