What is proper filter or hook action to add data to the $post object?
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
Leave an answer