Question

How can I list all post from a taxonomy like example i have "studios"

Example :

Studios:

-list property

-list property

-list property

-list property

/**
 * Custom taxonomies
 */
function aviators_properties_create_taxonomies() {


    $property_types_labels = array(
        'name'              => __( 'Property Types', 'aviators' ),
        'singular_name'     => __( 'Property Type', 'aviators' ),
        'search_items'      => __( 'Search Property Types', 'aviators' ),
        'all_items'         => __( 'All Property Types', 'aviators' ),
        'parent_item'       => __( 'Parent Property Type', 'aviators' ),
        'parent_item_colon' => __( 'Parent Property Type:', 'aviators' ),
        'edit_item'         => __( 'Edit Property Type', 'aviators' ),
        'update_item'       => __( 'Update Property Type', 'aviators' ),
        'add_new_item'      => __( 'Add New Property Type', 'aviators' ),
        'new_item_name'     => __( 'New Property Type', 'aviators' ),
        'menu_name'         => __( 'Property Type', 'aviators' ),
    );

    register_taxonomy( 'property_types', 'property', array(
        'labels'       => $property_types_labels,
        'hierarchical' => true,
        'query_var'    => 'property_type',
        'rewrite'      => array( 'slug' => __( 'property-type', 'aviators' ) ),
        'public'       => true,
        'show_ui'      => true,
    ) );

}

add_action( 'init', 'aviators_properties_create_taxonomies', 0 );
Était-ce utile?

La solution

Use tax query (http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters)

             $args['tax_query'] = array(
                array(
                    'taxonomy'  => 'property_types'
                    ,'field'    => 'slug'
                    ,'terms'    => 'your_slug'
                )
            );

Autres conseils

Thanks, work like a charm

this is my code:

<?php
$args=array(
  'post_type' => 'property',
  'taxonomy' => 'property_types',
  'caller_get_posts'=> 0,
  'tax_query' => array(
    array(
        'taxonomy' => 'property_types',
        'terms' => 'rooms',
        'field' => 'slug',
        'include_children' => true,
        'operator' => 'IN'
    )
),
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
  <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>


        <?php
  endwhile;
}
wp_reset_query();  // Restore global post data stomped by the_post().

?>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top