• Hi, there! I’m trying to do something unique and I’ve struggled to find documentation that would work. Basically, I’d like to reveal a random featured photo of a custom content type, but only if it has a certain category.

    I was able to get random featured photos of a custom content type to appear on the page (which you’ll see when you click the link to the page.) However, I tried to add a line that specified displaying only content from a specific category (in this case “left”). When I do this, the content no longer displays.

    I think that this issue may be arising because the term “left” is a part of a custom taxonomy that I created, but I don’t know for sure. Any help would be very useful. Thank you!

    function pholef() {
    ?>
    <?php
    $args = array(
        'category_name' => 'left',
        'post_type' => 'photos',
        'posts_per_page' => 1,
        'orderby'   => 'rand',
    );
    $the_query = new WP_Query( $args ); ?>
    
    <?php if ( $the_query->have_posts() ) : ?>
            <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                <div class="quarter">						
                    <?php if ( get_the_post_thumbnail() ) : /* Show the featured image if there is one */ ?>									 
                        <?php the_post_thumbnail(); ?>
                    <?php endif; ?>
                </div>
            <?php endwhile; ?>
    
        <?php wp_reset_postdata(); ?>
    
    <?php endif; ?>
    <?php
    }
    add_action('hook_top_pholef', 'pholef');

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Displaying posts of custom type based on custom taxonomy category’ is closed to new replies.