
Tagged: add_post_meta, create post, dynamic template, post, post type, update_post_meta
-
AuthorPosts
-
September 19, 2013 at 12:59 am #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!
September 19, 2013 at 4:05 pm #163639Hello 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,
DevinSeptember 19, 2013 at 4:48 pm #163662I’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: https://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.
September 20, 2013 at 9:07 am #163963Hi,
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.
September 20, 2013 at 3:18 pm #164080Awesome, thanks Dude. I will give that a shot.
-
AuthorPosts
The topic ‘Trouble applying Dynamic Templates with add_post_meta()’ is closed to new replies.