Home › Forums › Front-end Issues › Attach uploads from post_content to post in frontend › Reply To: Attach uploads from post_content to post in frontend
Thank you!
I tried this, but it failed:
function my_save_post( $post_id ) {
$my_content = get_field('post_content', $post_id);
if($my_content){
preg_match_all('/wp-image-(\d+)/', $content, $matches);
$imagatt = $matches[1];
foreach( $imagatt as $imagat ):
$post_to_update = array(
'ID' => $imagat,
'post_parent' => $post_id
);
wp_update_post( $post_to_update );
endforeach;
}
}
add_action('acf/save_post', 'my_save_post', 20);
I also tried
$my_content = $_POST['post_content'];
instead of
$my_content = get_field('post_content', $post_id);
In template I use:
<?php acf_form(array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'upr',
),
'post_title' => true,
'post_content' => true,
'submit_value' => 'Add item'
)); ?>
Can you help me? I think the solution is not so far…
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.