Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other how to get custom posts for custom taxonomy ?

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #151710
    amis
    Participant

    hey everybody

    I am working in wordpress theme and i make custom post type called ‘videos’ and make taxonomy for it call types

    types will be like comedy , drama .. etc

    now i want to get custom posts under comedy only in one page and also for other types

    i have been created this page taxonomy-type.php and used this loop

    <?php if(have_posts()) : ?>
       <?php while(have_posts()) : the_post(); ?>
    // post here 
       <?php endwhile; ?>
    <?php else : ?>
    // not found 
    <?php endif; ?>
    

    but not work with me ! i hope anyone help me

    #151775
    Energ
    Participant

    You need to use a custom WP_query. Something like this:
    $args = array(
    ‘post_type’ => ‘post’,
    ‘tax_query’ => array(
    ‘relation’ => ‘AND’,
    array(
    ‘taxonomy’ => ‘movie_genre’,
    ‘field’ => ‘slug’,
    ‘terms’ => array( ‘action’, ‘comedy’ )
    ),
    array(
    ‘taxonomy’ => ‘actor’,
    ‘field’ => ‘id’,
    ‘terms’ => array( 103, 115, 206 ),
    ‘operator’ => ‘NOT IN’
    )
    )
    );
    $query = new WP_Query( $args );

    You can read more here.

    #151782
    amis
    Participant

    thx Energ

    i have been used this but not work with me

     <?php
    $args = array(
    'post_type' => 'videos',
    'tax_query' => array(
    'relation' => 'AND',
    ),
    array(
    'taxonomy' => 'type',
    'field' => 'slug',
    'terms' => array( $term->slug )
                        )
    );
    $query = new WP_Query( $args );
    ?>
    <?php if(have_posts()) : ?>
       <?php while(have_posts()) : the_post(); ?>
    

    i will show you what i want defiently

    i want when go to this link get what in it

    http://localhost/wp/?type=comedy (get comedy only )

    http://localhost/wp/?type=action (get action only)

    #151901
    Senff
    Participant

    To list all posts of type “videos” that have “comedy” checked in the custom taxonomy “type“:

    $args = array( 
        'post_type' => 'videos',
        'type' => 'comedy'
    );
    
    $loop = new WP_Query( $args );
    
    while ( $loop->have_posts() ) : $loop->the_post();
        echo '- '.get_the_title().'<br>';
        // other loopy stuff here
    endwhile;
    

    More info: http://www.senff.com/front-end/on-custom-taxonomies/

    #151919
    amis
    Participant

    thx Senff but not work with me

    the name of my page is taxonomy-videos.php
    and i want loop in it will be suitable for this

    http://localhost/wp/?type=comedy
    http://localhost/wp/?type=action
    http://localhost/wp/?type=drama

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Other’ is closed to new topics and replies.