SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Wordpress - Pull Latest posts from custom post types

    Hello all, I am implementing the popular Nivo Slidebar on my wordpress sidebar and I would need some help with my code.

    Basically I just want to show 5 slides which always contain the latest post from each of my review types namely:

    1. os_fashion
    2. os_travel
    3. os_watches
    4. os_gifts
    5. os_games

    I am having trouble figuring the code that needs to go on the loop... I figured out CSS, Jquery - I just need the php code which can do the above.

    I need to show the image and post title.

    Any help would be much appreciated!

    thanks
    Andy

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,603
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Use WP_Query and the post_type attribute. The post_type will be whatever string you used when you registered your custom post type.

    https://codex.wordpress.org/Class_Re...ype_Parameters
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Force Flow, this is very useful but i couldnt find an example that tells me how to show only 1 post from each of the 5 custom post types.. any help with the actual syntax?

    thanks
    Andy

  4. #4
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,603
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by neodjandre View Post
    Hi Force Flow, this is very useful but i couldnt find an example that tells me how to show only 1 post from each of the 5 custom post types.. any help with the actual syntax?
    The only method that I can think of is to do 5 different WP_Queries and set the "posts_per_page" attribute to 1 for each of them.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks! would your suggestion use less resources than 1 WP Query which lists the 5 latest posts with the tag "latest-posts" ? i.e. I am going to tag all posts with "latest-posts" and the Query will pick the last 5..

  6. #6
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,603
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Database queries are cheap. They're designed to run and return results quickly.

    Your proposed method puts a lot of burden on you to manage the content manually for a feature in your template that should be automatic.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •