Topic: Wordpress

Query all content, except the currently viewed post

This is a great snippet for WordPress, usually used in a sidebar for featured content. If you were looking at a post of some type of content, you could stop that same post from being listed in the sidebar as well by using this code.

$this_post = $post->ID;
$args = array( 'post_type' => 'career', 'post__not_in' => array($this_post), 'posts_per_page' => 3 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="entry-content">';
echo '</div>';

Query by Taxonomy

Taxonomies are extremely useful for categorizing content within your WordPress site. Building a query to show those post is something that I had trouble finding. So I’m posting this so other will be able to use it.

function cc_community_partner_query() {
    $args = array(
        'post_type' =&gt; 'partner',
        'posts_per_page' =&gt; 99,
        'tax_query' =&gt; array(
                'taxonomy' =&gt; 'partner-levels',
                'field' =&gt; 'slug',
                'terms' =&gt; 'community-partners',
                'operator' =&gt; 'NOT IN'
    $community_partners = new WP_Query( $args );
    return $community_partners;