Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type recipes which uses the archive-recipes.php template automatically.

I have a Wordpress page called Top Recipes which is set to use the archive-recipes.php template in the CMS.

When browsing to www.mysite.com/top-recipes/ I get the Top Recipes title displayed along with the Featured Image I set in the CMS followed by the list of recipes.

But the problem occurs when browsing to www.mysite.com/recipes/ The title and featured image are that of the latest recipe to be entered into the database.

How can I assign the /recipes custom post type archive to have the same title/ featured image as the Top Recipes page?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Your recipe archive itself doesn't have a post or page to attach meta such as featured images to.

Since you posted no code and my psychic powers are not working today, I'm going to assume that one of these is your situation:

  • Top recipes and the recipes archive are identical with no difference
  • Top recipes uses pre_get_posts to modify the main loop

I would advise you don't reuse archive-recipe.php, and instead have 3 files, the archive template, the page template, and the common code pulled in via get_template_part

Possible solutions, starting with the hackiest and moving towards the nicest:

  • use is_archive() to display a hardcoded featured image on the archive page but not when used as a page template
  • Do a search using WP_Query for posts of type page with the post meta matching the page template archive-recipes.php and display the first ones featured image
  • Add a dropdown menu in the backend options under reading allowing you to pick the top recipes page, then grab the ID via get_option on your archive page
  • Realise that a recipe archive and a top recipes list are not the same thing and that naming them the same and giving them the same template is bad design, bad implementation, bad seo, bad practice, bad user interaction, and utterly confusing.
share|improve this answer
    
Thanks for your helpful, albeit condescending answer :) I will rethink the way that the recipes section is structured as I would rather not hack things together. –  dclawson Feb 15 '13 at 12:50
    
I take pride in my sass –  Tom J Nowell Feb 15 '13 at 14:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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