Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am not able to get the data of post which i inserted by

wp_insert_post();

now i want to get the tags which i stored by

'tags_input' => array('thread_tag' => $tags)

and i also upload an image of this post as attachment, so could you please tell me how to retrieve the attachment?

share|improve this question

1 Answer 1

You can use:

$post_id = wp_insert_post($args);

to get the ID of the inserted post. You can try this:

   $terms = wp_get_object_terms($post_id, 'thread_tag');

to get the terms from your post with $post_id. You can check out the Codex:

http://codex.wordpress.org/Function_Reference/wp_get_object_terms

You can then use get_children()

$args = array(
'post_mime_type' => 'image',
'post_parent' => $post_id,
'post_type' => 'attachment'
);

$attachments = get_children( $args );

to fetch the attachments for this post. More on the Codex page:

http://codex.wordpress.org/Function_Reference/get_children

Edit:

To set the terms in the 'thread_tag' taxonomy for a given $post_id

wp_set_object_terms($post_id,array('term1','term2'),'thread_tag');

http://codex.wordpress.org/Function_Reference/wp_set_object_terms

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.