0

I am trying to show a list of the latest 3 custom post types in the footer, and while I am getting the permalink ok for the href, the title is not displaying. Here is the code I put in the footer:

$postslist = get_posts('numberposts=3&order=DESC&orderby=date&post_type=class');
foreach ($postslist as $post) :
setup_postdata($post);
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>

A plugin is generating the post type.

0

you need the WP_Query Before your Code:

<?php 
$allCat = array(
    'posts_per_page'    => 3,
    'tax_query'         => array(
        array(
            'taxonomy'  =>  'category-products',
            'field'     =>  'slug',
            'terms'     =>  'your-slug',

            )
    ) 
);

?>
    <?php $all_product = new WP_Query($allCat); ?>
    <?php if($all_product -> have_posts()) : ?>
        <?php while($all_product -> have_posts()) : 
            $all_product -> the_post(); ?>     

             <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

        <?php endwhile; ?>
    <?php endif; ?>
|improve this answer|||||
0

Try globalizing $post before your foreach as mentioned here

$postslist = get_posts('numberposts=3&order=DESC&orderby=date&post_type=class');
global $post;
foreach ($postslist as $post) :
    setup_postdata($post);
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.