Kris
Kris

Reputation: 155

WordPress - Cannot get custom fields to show on home page

I am trying to add the custom field "market" into the a href as links, which is working great on pages, however is not working on my home page.

The PHP is identical for both.

For the home page, the php is in the functions.php file, and for the theme-by-series page the PHP is in the page's .php file.

The page works, so it doesn't seem to be anything wrong with the PHP, seems more like it for some reason is not targeting the post id as it should.

Anyone know how to solve this?

Upvotes: 0

Views: 1572

Answers (2)

doublesharp
doublesharp

Reputation: 27687

Custom fields are saved per post/page, and this is likely why it's not loading on your index.php page. You need to replace $post->ID with the ID of the post/page you want to show your custom field for - the $post object is available on the page.php and single.php templates, which is why it works there. On the index page, it would only be available inside the loop.

Upvotes: 2

JamesHoux
JamesHoux

Reputation: 3497

Look up the WP Docs on how to Reset the main WP Loop Query:

http://codex.wordpress.org/Function_Reference/wp_reset_query

If you're getting different results in functions.php vs a page template, there's a good chance its because your page template has already started a query loop and its conflicting somehow. This is just off the cuff without looking at the code. I'm going by your description of the difference betweeen working and non-working models.

Upvotes: 0

Related Questions