Home › Forums › Front-end Issues › Nested Post Object Fields › Reply To: Nested Post Object Fields
I have a question on this topic. I have three post types. Notebooks -> Notebook Sections -> Notebook Pages. I have added two post object fields to the notebook pages. The first one picks the notebook the page goes into and I want the second one to only pull up the notebook sections that are children of the notebook selected. I also have a post object field on the notebook sections to choose the notebook parent to attach it to. This is the code I am using in my functions.php for that one.
function my_acf_save_post( $post_id ) {
// Get the selected post status
$value = get_field('notebook_section_post_parent', $post_id);
// Update current post
$post = array(
'ID' => $post_id,
'post_parent' => $value,
);
// Remove the action to avoid infinite loop
remove_action('acf/save_post', 'my_acf_save_post', 20);
// Update the post into the database
wp_update_post( $post );
// Add the action back
add_action('acf/save_post', 'my_acf_save_post', 20);
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 20);
So, how do I make the notebook section field on the notebook pages only pull up the children of the notebook selected? I’m really new to coding, so I just can’t wrap my head around it and how to do it without it all getting so complicated. I appreciate ANY advice. Thanks!
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.