I have created a custom post type called joke using custom post types ui plugin. I have enabled archives for that ctp. I would like to have a page that would display the daily (or monthly) joke, and also have a page that would display an archive of all previous jokes. Is it possible, and if so, can you point as to how it can be achieved?

  • How do you want to choose the top daily/monthly joke? To show all your jokes, you would be best to create a template for your CPT. See here: codex.wordpress.org/…
    – JMB
    Commented Dec 22, 2013 at 13:13
  • for the daily joke I would choose the most recent joke published, that has a publish date of the current date...
    – vobs
    Commented Dec 22, 2013 at 13:25

1 Answer 1


OK, following on from my comment above, I would suggest creating a template for your Jokes archive e.g. archive-my_jokes.php (where my_jokes is the name of your CPT). You can likely copy some template content from category.php or a similar existing template file to get started. To deal with showing the top joke, you'll need to put your code before any loop in your template. I'd suggest using wp_get_recent_posts (see here) to call one post from your CPT. For example:

$args = array(
    'numberposts' => 1,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'post-type' => 'my_jokes', //CPT slug here

$top_jokes = wp_get_recent_posts ($args);
     foreach ($top_jokes as $top_joke) {
        //Echo what you like here
        echo $top_joke['post_title'] . '<br />';
        echo $top_joke['post_content'];

The styling of the above output is up to you to sort out according to your theme/template/styling needs. N.B. The reason I used a foreach loop even though you only want one post is for flexibility later if you deicde you want more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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