• Hey Guys…
    (Have I ever mentioned how much I love this community? Well…I do!)

    I was wondering how I can query regular ‘post’ categories in custom posts? I figured out a simple query for the post, but I would like to add the category.

    I’m a bit confused by the command in the functions file which calls the taxonomies to be categories:

    ‘taxonomies’ => array(‘category’),

    I haven’t had much success with ‘cat => 3’ in my query.

    I know in custom posts–which is kind of frustrating–you can’t query the taxonomy. So I’m wondering if there’s a conflict somewhere? Should I be calling the taxonomy instead?

    Any help would be much appreciated.

    Here’s my query:

    `<?php
    query_posts(array(
    ‘post_type’ => ‘events’,
    ‘order’ => ‘ASC’

    ) );
    ?>`

    `

Viewing 3 replies - 1 through 3 (of 3 total)
  • It sounds like you need to specify the category term. Try this:

    <?php
    query_posts(array(
    'post_type' => 'events',
    'order' => 'ASC',
    'tax_query' => array(
       array(
    	'taxonomy' => 'category',
    	'field'    => 'slug',
    	'terms'    => array( '$term' ),
      ),
    ) );
    ?>

    //Replace $term with the category slug or array of slugs you would like displayed.

    Sorry, forgot to mention you can use the term ID instead of slug as well and provide the query with an array of the category term ids which is the default action.

    Thread Starter 914Digital

    (@soulstatic)

    Ah. I see! Awesome. Thanks!!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Use Categories In Custom Post Query’ is closed to new replies.