Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #163244

    I have a page template which allows a user to create a new post from the front end. This is being used for a business directory on a client site. The post is adding successfully and showing up entirely as expected except in one regard..

    The post type needs to display with a specific dynamic template (“dynamic_template_listings”) and I haven’t been able to successfully manipulate the post meta to apply this.

    I’ve attempted copying the meta key / value of a successful post (created by an admin in the back end) like so:

    
    $options = 'a:7:{s:6:"layout";s:25:"dynamic_template_listings";s:17:"dynamic_templates";s:8:"listings";s:27:"on_save_layout_dynamic_save";s:27:"on_save_layout_dynamic_save";s:15:"_slideshow_type";s:4:"fade";s:19:"_slideshow_position";s:3:"big";s:19:"_slideshow_autoplay";s:5:"false";s:19:"_slideshow_duration";s:1:"5";}';
    add_post_meta($id, "_avia_elements_avia_options_replete", $options);
    add_post_meta($id, "_avia_elements_theme_compatibility_mode", $options);
    

    The post meta shows up on the Edit Post page, but with a “s:307:” string fixed to the beginning of the $options string and no template applied to the post.

    If there is a known way around this, I could really use a hand! Thanks!

    #163639

    Hello FarenAgency!

    I’m not sure if this is doable but I’ve tagged the head of support who should at least be able to shed a bit of light on it one way or another.

    Regards,
    Devin

    #163662

    I’ve used a work-around for the time being by adding a blanket Category (‘listings’) to the post type on creation and filtering to a single-listings.php file housing the dynamic template – outlined here: http://www.kriesi.at/support/topic/set-custom-template-for-all-posts-in-category/.

    Had to add a filter hook in functions.php to route the category templates correctly (as I have been dealing with several similar post types), but it is working now.

    Still curious if there is a more proper way of doing this.

    Thanks.

    #163963

    Hi,
    Kriesi uses serialized data to store the post meta. You need to unserialize it to use it. I.e. replace your code

    
    $options = 'a:7:{s:6:"layout";s:25:"dynamic_template_listings";s:17:"dynamic_templates";s:8:"listings";s:27:"on_save_layout_dynamic_save";s:27:"on_save_layout_dynamic_save";s:15:"_slideshow_type";s:4:"fade";s:19:"_slideshow_position";s:3:"big";s:19:"_slideshow_autoplay";s:5:"false";s:19:"_slideshow_duration";s:1:"5";}';
    add_post_meta($id, "_avia_elements_avia_options_replete", $options);
    add_post_meta($id, "_avia_elements_theme_compatibility_mode", $options);
    

    with

    
    $options = 'a:7:{s:6:"layout";s:25:"dynamic_template_listings";s:17:"dynamic_templates";s:8:"listings";s:27:"on_save_layout_dynamic_save";s:27:"on_save_layout_dynamic_save";s:15:"_slideshow_type";s:4:"fade";s:19:"_slideshow_position";s:3:"big";s:19:"_slideshow_autoplay";s:5:"false";s:19:"_slideshow_duration";s:1:"5";}';
    $options = maybe_unserialize($options);
    add_post_meta($id, "_avia_elements_avia_options_replete", $options);
    add_post_meta($id, "_avia_elements_theme_compatibility_mode", $options);
    

    and it should work because it saves a proper array.

    #164080

    Awesome, thanks Dude. I will give that a shot.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Trouble applying Dynamic Templates with add_post_meta()’ is closed to new replies.