$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Suggestion to make posts have multiple associated items|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Suggestion to make posts have multiple associated items

matteradmin8PV0评论

I'm developing a WordPress theme and I need some expert advice to achieve a little complex result. My theme has a custom post type and that post type should have child items. For example the post is about a software and every time a new version is released, I need to update the post and add the new version info (URL, version number, file size etc.). Can this be achieved using meta data (custom fields) or is there some better way? Please guide me in a right direction.

I'm developing a WordPress theme and I need some expert advice to achieve a little complex result. My theme has a custom post type and that post type should have child items. For example the post is about a software and every time a new version is released, I need to update the post and add the new version info (URL, version number, file size etc.). Can this be achieved using meta data (custom fields) or is there some better way? Please guide me in a right direction.

Share Improve this question asked Feb 10, 2019 at 14:54 RehmatRehmat 1131 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You should be able to do this fairly easily with the save_post hook. When one of the child pages is saved your hook will fire and allow you to firstly check the post type, and then if the post is indeed a child of your main post, where you want to update the URL, version etc.

You can retrieve the child post values using ACF get_field:

$latest_version = get_field('software_version', $post->ID);

Then update your parent using the ACF update_field:

update_field('current_version', $latest_version, $post->post_parent);

Un-tested, but that gives you the basics.

Post a comment

comment list (0)

  1. No comments so far