admin管理员组文章数量:1406937
I have a custom post type that has a one to many relationship with another custom post type. Call them lesson
and topics
. Currently, I get $topics
as
$args = array(
'meta_key' => 'lesson_id',
'meta_value' => $post['post']->ID,
'post_type' => 'plugin-topic',
'post_status' => 'published',
'posts_per_page' => -1
);
$les_topics = get_posts($args);
However, when the $lesson
object is created by wordpress for first time, I would like to add $topics to it so that I can reference as $lesson->topics.
Can someone tell me the appropriate filter or action to use to accomplish that? I saw this
Adding additional data to WP_Post object
which suggests I shouldn't even do what I am asking to do but it isn't clear why this would be a bad thing.
thanks! Brian
I have a custom post type that has a one to many relationship with another custom post type. Call them lesson
and topics
. Currently, I get $topics
as
$args = array(
'meta_key' => 'lesson_id',
'meta_value' => $post['post']->ID,
'post_type' => 'plugin-topic',
'post_status' => 'published',
'posts_per_page' => -1
);
$les_topics = get_posts($args);
However, when the $lesson
object is created by wordpress for first time, I would like to add $topics to it so that I can reference as $lesson->topics.
Can someone tell me the appropriate filter or action to use to accomplish that? I saw this
Adding additional data to WP_Post object
which suggests I shouldn't even do what I am asking to do but it isn't clear why this would be a bad thing.
thanks! Brian
Share Improve this question asked Oct 27, 2019 at 9:08 BrianBrian 3372 silver badges11 bronze badges1 Answer
Reset to default 0According to https://developer.wordpress/reference/functions/wp_insert_post/ (looking at the source code) you could use wp_insert_post_data
link and inject your relation, whenever a post is inserted.
$post
is usually a global variable though when a page is loaded, which you can adjust using the_post
link
本文标签: What is proper filter or hook action to add data to the post object
版权声明:本文标题:What is proper filter or hook action to add data to the $post object? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745051670a2639693.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论