WordPress.org

Ready to get started?Download WordPress

Forums

Get all posts from a taxonomy (6 posts)

  1. Sudar
    Member
    Posted 3 years ago #

    I have a custom taxonomy called country, which is associated with certain posts with terms like "India", "US", "UK" etc.

    Now I want to retrieve all posts that belong to the "country" taxonomy, irrespective of which term ("India", "US" etc) they have.

    Is it possible to do it or do I have to write a custom SQL query to retrieve it?

  2. chinmoy
    Member
    Posted 3 years ago #

    see this sample

    $args = array(
    	'tax_query' =>
    		'relation' => 'AND',
    		array(
    			'taxonomy' => 'movie_janner',
    			'field' => 'slug',
    			'terms' => array( 'action', 'commedy' ),
    		),
    		array(
    			'taxonomy' => 'actor',
    			'field' => 'id',
    			'terms' => array( 103, 115, 206 ),
    			'operator' => 'NOT IN',
    		)
    )
    query_posts( $args );
  3. Sudar
    Member
    Posted 3 years ago #

    In the doc it is specified that "Multiple Taxonomy Handling" is available only from WordPress 3.1.

    I want something which can work in the current version of WordPress.

  4. chinmoy
    Member
    Posted 3 years ago #

    try this query_posts( array('country') ); or thisquery_posts( array('country' => array("India", "US", "UK")) );

  5. Sudar
    Member
    Posted 3 years ago #

    query_posts( array('country') ); doesn't work.

    query_posts( array('country' => array("India", "US", "UK")) );

    I cannot use this query, because there are lot of terms and I cannot list all of them.

  6. chinmoy
    Member
    Posted 3 years ago #

    may be it will help query_posts('taxonomy'=> 'country');

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags