So I'm wondering exactly how I could display my latest post on a page only in certain conditions. I've been looking over the conditions page in the codex, but I'm not seeing how I could do what I have in mind. For example: I will have multiple vendors selling on my site. Each vendor will have their own page on the site. There will be one featured item for sale on the home page,(which we figured out how to do here: Display newest post's custom field content on homepage, daily ) and when it happens to be a certain vendor's item, I would like the post to display on their specific page as well. So I would need to only show the newest post(again, I got help with this in the provided link) on their page, ONLY when it happens to be their item. As always, thanks in advance!

  • so are you asking to display the vendor's information on the home page, or are you asking to highlight the featured item on the vendor's page? – Jen Oct 1 '12 at 3:56
  • Also, what's the relationship between a Product and a Vendor? how have you set them up? How do you decide when a vendor should be the featured one - is it always the same vendor forever, or does that change often? Do you have a way to change the featured vendor on the back-end, or do you just plan on changing it in the code every once and a while? – Jen Oct 1 '12 at 3:56
  • I'm trying to highlight the featured item on the vendor's page, if it happens to be their item. It will be changed often, maybe even daily if it takes off well enough. Basically, if the vendor agrees to offer a product for a discount, their item will be featured on the home page. When that happens, I would like for that same post to be shown on their individual page. It will be changed in the backend, via custom fields if all goes as planned. – Anthony Myers Oct 2 '12 at 0:54

Possibly you could wrap the code on the vendor's page in a comparison. So if the vendor's name is the Title of their page, and the newest post has a meta field that hold's the vendor's name, it could look like this:

$my_most_recent_post = get_posts( 'numberposts=1' );
$my_most_recent_post_id = $my_most_recent_post[0]->ID;
// Get the featured item's meta information here
$meta = get_post_meta($my_most_recent_post_id, 'my_custom_meta', $single = true);

if ( $meta == 'Featured Vendor' )
    // display the featured vendor information here

I'm assuming that you're storing vendor information with all your product entries. Whether you store the title of the vendor, the unique ID, or the slug, that comparison should be similar.

  • Very cool! Thank you for your reply! I will give this a go. – Anthony Myers Aug 27 '12 at 23:54
  • Do you think you'd have a few minutes to help me with this further? I have been trying to get this and other variations of this to work all morning, but I'm not having any luck at all. nothing is being output whatsoever. – Anthony Myers Sep 30 '12 at 19:26
  • So basically, I'm on the vendor's page, and what your code is saying is that if the Title of the vendors page matches a custom field on the newest post, then I should be able to display the newest post on the vendors page. For example, let's say the vendor's name and page is Awesome Vendor, then all I would need to do is add a custom field to the newest post that holds, "Awesome Vendor" in it right? It's just not working. Do I need start the loop? Because I'm trying that now, and that's not working either. – Anthony Myers Sep 30 '12 at 19:30
  • edited for a bit more clarity. – Jen Oct 1 '12 at 3:48
  • Ok awesome! Thank you for replying again. I will give this a try ASAP, and report back. – Anthony Myers Oct 2 '12 at 0:57

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.