Home › Forums › Backend Issues (wp-admin) › acf/save_post Shortcodes › Reply To: acf/save_post Shortcodes
Ok, this is the entire function:
function builder_save_post($post_id){
global $post;
global $saving_build;
$saving_build = true;
$builder_post = array();
$builder_post['ID'] = $post_id;
if ( ! wp_is_post_revision( $post_id ) ){
$set_template = get_post_meta( $post_id, '_wp_page_template', true );
$do_build = false;
$builder_out = '';
if( '_template-acf-builder.php' == $set_template && have_rows('bc_builder') ){
$builder_out .= '<div class="bc_builder">';
while( have_rows('bc_builder') ){
the_row();
$layout = get_row_layout();
if( !empty($layout) ){
ob_start();
get_template_part('layout/builder', $layout.'-save_post');
$builder_out .= ob_get_clean();
}
}
$builder_out .= '</div>';
$do_build = true;
}
$builder_post['post_content'] = $builder_out;
if($do_build){
remove_filter('acf/save_post', 'builder_save_post', 20);
wp_update_post( $builder_post );
add_action('acf/save_post', 'builder_save_post', 20);
}
$saving_build = false;
}
}
add_action('acf/save_post', 'builder_save_post', 20);
As you can see i´m using get_template_part to get php files iniside /layout/ folder, this templates are named with same name of the flexible layout ($layout variable).
So if layout is “gallery”, the template is layout/builder-gallery-save_post.php.
It works perfectly, data is saved the right way. But….
Let´s say i inside on of those templates i have something like this:
The title: "<? the_title() ?>"
The shortcode: <? echo do_shortcode('[shortcode]'); ?>
Where “shortcode” is just an example, could be any shortcode. Let´s imagine that this shortcode outputs only a string like “Hello”, so, this is what is saved into the post_content till now:
Post title: "My post title"
The shortcode: Hello
The last “The shortcode: Hello” is the problem, i don´t whant the result of the shortcode, i want this to be saved into post_content:
Post title: "My post title"
The shortcode: [shortcode]
That´s it, i need to save just “[shortcode]” into the post_content, not the “Hello” result that this shortcode returns. So, i guess there´s must be some way to unfilter the do_shortcode before i get the template part or something like that.
Sorry, it´s a complex situation and is hard to explain 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.