Jump to content


This topic is now archived and is closed to further replies.


To show a random CPT post in a section?

Recommended Posts


The result I am after is a section on a homepage which displays a single post's featured image, along with the post's title.

The post should be randomly chosen, on page load, among all the posts under a single CPT.


I can think of a number of ways to accomplish part of this but am wondering if one is considered best.

A sticking point is the random requirement.


FWIW, besides the usual DMS2 extensions and other PageLines theme-specific sections, I have ElSue's SingleBits, PageLines Power Loop, Special Recent Posts Pro, as well as Sidebar & Widget Manager for WordPress.

Share this post

Link to post
Share on other sites



There is no section that can display a random post. Therefore, you will want to create your own section and use the rand function see here fore more information - https://codex.wordpress.org/Class_Reference/WP_Query

Please search our forums, before posting!

Share this post

Link to post
Share on other sites

Thanks Danny!

Share this post

Link to post
Share on other sites


I might have solved this with the Masonic Gallery section:

  • Add the following to the child theme's functions.php file
// Limits the number of Masonic Gallery posts on the Page to 1 //
add_filter( 'pl_opt-masonic_total', function() { return 1; } );
  • Then, in the 'Sort Elements by Postdate' drop down in the Masonic Gallery section options, choose Random

It seems to work as intended.

Share this post

Link to post
Share on other sites

  • Similar Content

    • Lisa Haran
      By Lisa Haran+
      I have a map here http://www.iloveoffset.com/maps/
      I want to add several pointer locations to the map, but when I do they do not appear.
      On this map there are 2 pointer locations and as you can there is only one visible.
      Earlier today I added 7 and could only see 4 so there is something odd going on.
      My theme is up to date
    • clj182
      By clj182+
      I've been having trouble unlocking the template section for past couple of weeks. When I try clicking nothing happens. 
      I've deleted my custom css and removed plugins. Im down to having only the following plugins:
      Contact Form 7
      DMS Professional Tools
      Pagelines Updater
      It was working fine before i have no idea what's going on with it.
    • flourishdesignstudio
      By flourishdesignstudio+
      My DMS 2 site http://www.heart-stone.com/ will not save any new custom css... I can still edit templates and publish those but any custom css that I enter never saves.
      All WP files, themes, and plugins are up to date. 
      Any thought about what might be causing this?
    • flourishdesignstudio
      By flourishdesignstudio+
      Is there a way to edit the custom CSS via FTP? I know I can edit the custom code in the Chrome editor but is there a file path I can use to find and edit the CSS directly from our FTP?
      Thanks in advance for the help!
    • nizami
      By nizami+
      Using navbar section with correctly configured WP menu to display main navigation at https://elenaangel.com. 
      All fine in desktop viewport. Menu displays twice in hamburger mode. How to fix this please?