Tagged: acf, custom post, SCF, wpallimport
-
AuthorPosts
-
December 6, 2024 at 9:15 pm #1473127
Hi there,
I am using Secure Custom Fields and I have set up a template using the ALB.
Now I need to import lots of posts using “WP All Import”.Everything works great, except that I have to manually open each imported post, click “Advanced Layout Editor” and select the custom layout. I have tried to use a shortcode in post content during import, which does not work.
1. Can I automatically set the custom layout to all imported posts? In general I find it a bit cumbersome to always use the ALB on each custom post to select the template (and nothing else).
alternatively:
2. Is there a way to ignore the post content and always set the template to a specific template for all posts belonging to a certain custom post type?Thank you in advance!
Best,
HenningDecember 9, 2024 at 5:15 am #1473195Hey henningtillmann,
Thank you for the inquiry.
You can try this hook in the functions.php file, but make sure to create a site backup or restore point before doing so:
function ava_update_custom_fields_for_post_type() { $post_type = 'your_post_type'; $posts = get_posts(array( 'post_type' => $post_type, 'posts_per_page' => -1, 'post_status' => 'any', 'fields' => 'ids', )); if (!empty($posts)) { foreach ($posts as $post_id) { update_post_meta($post_id, '_aviaLayoutBuilder_active', 'active'); update_post_meta($post_id, '_aviaLayoutBuilderCleanData', '[av_custom_layout link=\'alb_custom_layout,653\' av_uid=\'av-m3u7m8lu\' sc_version=\'1.0\']'); update_post_meta($post_id, '_avia_builder_shortcode_tree', 'a:1:{i:0;a:3:{s:3:"tag";s:16:"av_custom_layout";s:7:"content";a:0:{}s:5:"index";i:0;}}'); update_post_meta($post_id, '_avia_sc_parser_state', 'disabled'); update_post_meta($post_id, '_av_alb_posts_elements_state', 'a:1:{s:16:"av_custom_layout";b:1;}'); update_post_meta($post_id, '_av_el_mgr_version', '1.0'); } } } add_action('init', 'ava_update_custom_fields_for_post_type');
Just refresh the dashboard once, then remove the hook immediately. This will create the necessary custom fields for each item in the custom post type and enable the ALB automatically. Make sure to update the value 653 with the actual ID of the custom layout:
update_post_meta($post_id, '_aviaLayoutBuilderCleanData', '[av_custom_layout link=\'alb_custom_layout,653\' av_uid=\'av-m3u7m8lu\' sc_version=\'1.0\']');
And place the name or slug of the post type here:
$post_type = 'your_post_type';
Best regards,
IsmaelDecember 9, 2024 at 7:10 pm #1473275Awesome! Thank you so much! I will test this when I have the real data (probably end of this week).
December 10, 2024 at 1:27 pm #1473346Hi,
We’ll keep this thread open. Let us know when you’re ready to proceed.
Best regards,
IsmaelDecember 16, 2024 at 8:52 pm #1473788Hi Ismael,
I still haven’t received the final data so I haven’t done the import yet.
Could you please add one line so every imported custom post has the “hide headers on this page” layout setting?Thank you!!
Best,
HenningDecember 17, 2024 at 6:05 am #1473810Hi,
Thank you for the update.
We updated the filter to include the post meta “header_transparency” with the value “header_transparent header_hidden”.
function ava_update_custom_fields_for_post_type() { $post_type = 'your_post_type'; $posts = get_posts(array( 'post_type' => $post_type, 'posts_per_page' => -1, 'post_status' => 'any', 'fields' => 'ids', )); if (!empty($posts)) { foreach ($posts as $post_id) { update_post_meta($post_id, '_aviaLayoutBuilder_active', 'active'); update_post_meta($post_id, '_aviaLayoutBuilderCleanData', '[av_custom_layout link=\'alb_custom_layout,653\' av_uid=\'av-m3u7m8lu\' sc_version=\'1.0\']'); update_post_meta($post_id, '_avia_builder_shortcode_tree', 'a:1:{i:0;a:3:{s:3:"tag";s:16:"av_custom_layout";s:7:"content";a:0:{}s:5:"index";i:0;}}'); update_post_meta($post_id, '_avia_sc_parser_state', 'disabled'); update_post_meta($post_id, '_av_alb_posts_elements_state', 'a:1:{s:16:"av_custom_layout";b:1;}'); update_post_meta($post_id, '_av_el_mgr_version', '1.0'); update_post_meta($post_id, 'header_transparency', 'header_transparent header_hidden'); } } } add_action('init', 'ava_update_custom_fields_for_post_type');
Please make sure to create a backup of your site before proceeding.
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.