I'm trying to get a plugin to read the post metadata of an attachment, and it's used to post content I am using the following in my subjects function.php:
add_action ('afip_created_post', 'get_desc', 10, 2); Function get_desc ($ post_id, $ attachment_id) {$ postmeta = get_post_meta ($ attachment_id, '_wp_attachment_metadata', is true); $ Meta = $ postmeta ['image_mata']; $ Mmwwdesc = $ meta ['description']; Wp_update_post (array ('id' = & gt; $ post_id, 'post_content' = & gt; $ mmwwdesc)); } To hook more functions, use this line in the plugin
do_action ('afip_created_post', $ new_post_id, $ post_id); If I fill the varibale "$ attachment_id" with the number from any other post then "15", I have been put in the published post. If I change the output to wp_update_post (array ('id' = & gt; $ post_id, 'post_content' = & gt; $ attachment_id); I get an ID number in the published postal body. I do not understand why the original code does not work, because $ attachment_id is properly defined. I'm just starting with php, is there anything clear that I am doing wrong? Is the variable $ attachment_id being echoed when it should be returned, or some technical? Background: I call two WordPress plugins, a Media Metadata Workflow Wizard (MMWW), and the other is Automated Featured Image Post (AFIP). MMWW removes image metadata and writes it into database in the form of post meta. AFIP creates new posts using the uploaded media, and setting the post as a thumbnail, adds each image to a post. I do not think the function is called when no issue of metadata is being prepared This is because AFIP creates a post after uploading the media, and its meta database was written to. I am also making my function as an update of the post, after that it has been made.
I have not done extensive search and trial and error successfully Can anyone help me?
Thank you!
I think your issue is here that the get_post_meta function is returning blank in function.php this problem The way to deal with, to back up the data in your POT meta is to use a MYSQL query with WordPress.
First you need a global $ wpdb object, so that at the beginning of your function, type: global $ wpdb; Then you need to take the get_post_meta action via mysql and $ wpdb objects: $ postmeta = $ wpdb-> Get_var (Select "Meta_Wall from $ FROM Wpdb-> postmeta" WHERE meta_key = '_wp_attachment_metadata' and post_id = $ attachment_id "); replace your get_post_meta line with wpdb query And you should be okay.
No comments:
Post a Comment