0
votes

I want to filter my query results just before the_loop starts in word press. I only want the results having term_id or term_taxonomy_id equal to 1.

query_posts('post_type=my_post&term_id=1&posts_per_page=6');

This is returning all rows, I am new to word press so I am not sure that we can use term_id in query_posts. Is there any other way to do it?

2
What is the taxonomy for the term_id ? - The Alpha
name of taxonomy is I am giving in post_type=my_posts(taxonomy name). - Naveen
This is post type not the taxonomy, in which taxonomy your custom posts belong to ? - The Alpha
I have not created custom post type, I have created one custom taxonomy using register_taxonomy function and this taxonomy is in wp_term_taxonomy table. Its giving results for all terms from table wp_terms. My url : base/taxonomy_name/slug_of_term. But taxonomy.php page is not giving correct results so I am re writing query again. - Naveen
What is the taxonomy name you've used when you registered it ? - The Alpha

2 Answers

0
votes

Actually, the post type is not the taxonomy, post type is basically post, page, Attachment, Revision, Navigation Menu and the Custom Post Types and to create a custom post type we use register_post_type(), so you didn't create a custom post type (that I've got from your comments) instead, you've created a custom taxonomy using register_taxonomy() function and in this case the first parameter in the register_taxonomy() is the taxonomy name and the second parameter is the name of the object type for the taxonomy and object-types can be built-in Post Type or any Custom Post Type that may be already registered. So, according to your given example bellow

register_taxonomy( 
    'mumG', 
    'mumT', 
    array( 
        'label' => __( 'Label' ),
        'show_ui' => false,
    ) 
);

In the code above, you have created a custom taxonomy and it's name is mumG and the second parameter mumT is used as the object type for the taxonomy and it seems there is no such an object (post_type) in the WordPress unless you don't register/create one custom post type using register_post_type() function. So, if you don't want to create a custom post type for this taxonomy, then you should use the built-in post type post in the place of mumT as post type and can use following query to retrieve

$args = array( 
        'post_type' => 'post', // if post_type is post
        'showposts' => -1,
        'tax_query' => array(
        array(
            'taxonomy' => 'mumG',
            'terms' => 1,
            'field' => 'term_id',
        )
    ),
    'orderby' => 'title',
    'order' => 'ASC' 
);
query_posts( $args );

Otherwise, if you want to use a custom post type, then you have to create a custom post type first and then use the name of the custom post in the place of post (the second parameter) like

register_taxonomy( 
    'mumG', 
    'yourCustomPostName', // if you have a post_type of 'yourCustomPostName'
    ......
);

and use 'post_type' => 'yourCustomPostName' in the query. Please read these documentations for better understanding, register_taxonomy(), register_post_type() and query_posts() on the Codex.

0
votes

Replace taxonomy category name (sliders_category) to your taxonomy category name.

$args = array(
                'tax_query' => array(
                                    array(
                                            'taxonomy' => 'sliders_category',
                                            'field' => 'id',
                                            'terms' => '1'
                                          )

                            ),
                'post_type'=>'my_post',
                'order'=>'ASC',
                'posts_per_page'=>6

                );

query_posts($args);