WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Post Types and titles (6 posts)

  1. bobquznie
    Member
    Posted 9 months ago #

    OK. Having trouble here. Below, bold part in the code, is where I'm having troubles. I have a section that needs to pull the 4 latest posts from an array of custom post types. On top of the image I need it to say what "category," custom post type, that post is in. Right now, it doesn't pull any information with the code I have inserted. I am searching the Codex for any answer and am trying whatever I find but if anyone has any input, it would be very helpful. Thank you!

    <section class="info">
                    <?php
                            query_posts(array(
                                    'post_type' => array('infographics','ebooks','whitepapers','case-studies'),
                                    'posts_per_page' => 4,
                            ));
                    ?>
                    <?php if(have_posts()):?>
                    <header class="title">
                            <div class="title-holder">
                                    <h2>Latest Retail Info & Resources</h2>
                                    <p>The latest in our original research. All for you.</p>
                            </div>
                            <?php if(function_exists('get_field')):?>
                            <div class="btn-holder">
                                <?php if(function_exists('get_field')):?>
                                <?php $category = get_the_category();
                                $value = get_field('see_our_full', 'category_2'); ?>
                                 <a href="http://ricssoftware.wpengine.com/resources/">See our Full Library of Resources</a>
                                 <?php endif;?>
                            </div>
                            <?php endif;?>
                    </header>
                    <div class="post-list">
                    <?php while(have_posts()): the_post();?>
                            <article class="post">
                                    <div class="image-holder">
                                        <?php if(has_post_thumbnail()):?>
                                            <a href="<?php the_permalink();?>">
                                                    <?php the_post_thumbnail('home-post-thumbnail_148_137');?>
                                            </a>
                                        <?php endif;?>
                                            <span class="add"><strong><?php post_type_archive_title(); ?></strong></span>
                                    </div>
                                    <div class="description">
                                            <h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
                                            <?php the_excerpt(); ?>
                                    </div>
                            </article>
                    <?php endwhile;?>
                    </div>
                    <?php endif;?>
                    <?php wp_reset_query();?>
            </section>
  2. bobquznie
    Member
    Posted 9 months ago #

    Sorry, the code I was referring to is <?php post_type_archive_title(); ?>. Should've known that it would just put STRONG syntax around it.

  3. mindctrl
    Member
    Posted 9 months ago #

    get_post_type will retrieve the post type, and get_the_category will retrieve the category.

  4. bobquznie
    Member
    Posted 9 months ago #

    Neither one of has worked in this situation.

  5. bobquznie
    Member
    Posted 9 months ago #

    Ok. Now I feel dumb! get_post_type was right but forgot a little tidbit. <?php echo get_post_type(); ?>

  6. mindctrl
    Member
    Posted 9 months ago #

    Good news!

Reply

You must log in to post.

About this Topic