add_post_meta _wp_page_template no longer sets dynamic page template (5 posts)

  1. shawmutsteve
    Posted 3 years ago #

    I see there is a new way to get the page template.

    I've been using a fairly well discussed method to SET the page template for dynamic pages. We want these pages to be full width, so depending on the theme, the designer can set the template for these dynamic pages in their settings.

    Yesterday, dynamic pages were correctly setting the page template using:
    add_post_meta($posts[0]->ID, '_wp_page_template', $use_template, TRUE);

    After upgrading to WP 3.4, this no longer works, and we get the default template.

    Any thoughts?

    Thank you

  2. Jelle82
    Posted 3 years ago #

    What you can do is add a variable to your page-template like, $pg_template = 'movies';, then when you need to check what template the page is using you do global $pg_template; and if ( $pg_template == 'movies') { //do cool stuff }.

    But it is not a nice workaround, I think and I have been using your code also, untill now when I noticed this doesn't work anymore after 3.4.

  3. Jelle82
    Posted 3 years ago #

    It seems there is a new function that does this get_page_template_slug( $id = null ).

    From the release page of 3.4:

    Introduce get_page_template_slug( $id = null ) to return a page's template (like "showcase.php"); returns false if post ID is not a page, and an empty string for the default page template; use the function across core.


    It didn't work and I checked the code. get_page_template_slug( $id = null ) also uses $template = get_post_meta( $post->ID, '_wp_page_template', true );.

  4. shawmutsteve
    Posted 3 years ago #

    Yes - but I'm looking for a way to SET the page template that actually works in 3.4.

    And my pages are dynamic - they have fake post ids that do not actually exist in wp_posts or in wp_postmeta.

    I am using a method to force a page template that is documented in the Codex help, but it's no longer working in 3.4. :(


  5. Jelle82
    Posted 3 years ago #

    Now I understand what you're trying to do.

    The problem is still that _wp_page_template doesn't seems to be a metakey anymore. So you can't set it.

    Anyone else having trouble with getting a value for _wp_page_template?

Topic Closed

This topic has been closed to new replies.

About this Topic