0

I have a parent page with multiple Child Pages.

On the child page template I have an include which has customfields. This works perfectly. The custom fields are on the child page in wordpress.

The custom fields are all within page-customfield-3.php and included in page.php to display them.

I included page-customfield-3.php within page-parent.php and it does not display the custom fields. I have included a link to a github gist with the code for each file as it is very long otherwise.

   CURRENTLY WORKING           
      Page.php
          |
Page-customfield-3.php 


 CURRENTLY NOT WORKING           
    Page-parent.php
          |
Page-customfield-3.php  

https://gist.github.com/BHWD/9b30911c66337c5408e2

1
  • Please, post the relevant code in your question, not in external sources.
    – cybmeta
    Commented Dec 9, 2014 at 11:54

1 Answer 1

0

Your problem is that you are putting the page result in $page. While the normal commands like the_title() and get_field() will look for the $post variable if you are not setting a seperate ID of which you want the title.

I once did this by creating a backup of the $post variable, and then just put each post i wanted to include on the parent page in the $post variable. Then included the .php files, and every normal command like the_title(); & get_field(); works like it would normally would. But this is dirty, and there is probably a much better way to accomplish this.

You should probably just replace the main query with your get_posts query. Afterwards you should reset & restore the wp_query.

An other option would be to alter the page-customfield-3.php to include the $page variable you are setting in your page-parent.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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