Query for recent FAQs using query_posts or get_posts
-
Thank you for this brilliant plugin – it does exactly what I need it to do and it does it beautifully. ??
I could use some help in constructing a query to show the most recent X number of FAQs in a sidebar widget, my code is not working.
Rather than hardcoding in the slug, I need to find it using the query – when looking at my FAQs page source code, I see that the ID of the FAQ is the Post->ID, so I’m using this:
<ul> <?php query_posts( array( 'post_type' => 'faq', 'posts_per_page' => 5 ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li><a href="<?php get_site_url(); ?>/faqs/#faq-<?php echo $post->ID ?>"><?php the_title(); ?></a></li> <?php endwhile; endif; wp_reset_query(); ?> </ul>
This works great to produce a short list for my sidebar of the 5 most recent FAQs, but the linking isn’t right – they all go to a link that is this:
https://myrealdomain.com/faqs/#faq-
That’s it – no post ID…..so each link takes you to the FAQ page, but not directly to the linked FAQ.
I’m sure I’m missing something very simple, but I cannot figure it out…..any suggestions please?
- The topic ‘Query for recent FAQs using query_posts or get_posts’ is closed to new replies.