{"id":2575,"date":"2022-03-22T10:38:08","date_gmt":"2022-03-22T05:08:08","guid":{"rendered":"https:\/\/imageattributespro.com\/?post_type=codex&p=2575"},"modified":"2022-06-06T00:07:41","modified_gmt":"2022-06-05T18:37:41","slug":"iaffpro_update_attributes_in_post_by_post_id","status":"publish","type":"codex","link":"https:\/\/imageattributespro.com\/codex\/iaffpro_update_attributes_in_post_by_post_id\/","title":{"rendered":"iaffpro_update_attributes_in_post_by_post_id()"},"content":{"rendered":"\n

Update image attributes of all images in a given post. Post can be specified by passing post ID or post object. <\/p>\n\n\n\n

Image attributes will be updated as per the Bulk Updater Settings<\/code> of Image Attributes Pro. <\/p>\n\n\n\n

iaffpro_update_attributes_in_post_by_post_id( $post_id );<\/strong><\/code><\/pre>\n\n\n\n
  • Requires Image Attributes Pro 3.0 and above.<\/li>
  • Accepts the post ID ($post_id) as a parameter. <\/li>
  • Does not return anything. <\/li>
  • Can be used for posts, pages, WooCommerce products and any custom post type. <\/li><\/ul>\n\n\n\n

    Example Usages<\/h2>\n\n\n\n
    \/\/ Update image attributes of all images for a post with ID 247\niaffpro_update_attributes_in_post_by_post_id( 247 );<\/code><\/pre>\n\n\n\n
    \/**\n * Update image attributes as per the Bulk Updater Settings of Image Attributes Pro \n * when a post is saved or updated. \n * \n * @author Arun Basil Lal\n * @link https:\/\/imageattributespro.com\/codex\/iaffpro_update_attributes_in_post_by_post_id\/\n *\/\nfunction prefix_iap_update_image_attributes_on_save_post( $post_id ) {\n\n\tif ( ! function_exists( 'iaffpro_update_attributes_in_post_by_post_id' ) ) {\n\t\treturn;\n\t}\n\n\t\/\/ post_id from save_post will be the ID of the revision. Finding parent post_id.\n\tif ( $post_parent_id = wp_get_post_parent_id( $post_id ) ) {\n\t\t$post_id = $post_parent_id;\n\t}\n\n\t\/**\n\t * iaffpro_update_attributes_in_post_by_post_id() will call save_post again.\n\t * To prevent this, unhook action right before. \n\t * \n\t * @link https:\/\/developer.wordpress.org\/reference\/hooks\/save_post\/#avoiding-infinite-loops\n\t *\/\n\tremove_action( 'save_post', 'prefix_iap_update_image_attributes_on_save_post' );\n    \n\tiaffpro_update_attributes_in_post_by_post_id( $post_id );\n}\nadd_action( 'save_post', 'prefix_iap_update_image_attributes_on_save_post' );<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

    Update image attributes (image title, image alt text) of all images in a given post. Post can be specified by passing WordPress post ID or WordPress post object. <\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":[],"tags":[],"codex-type":[28],"_links":{"self":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex\/2575"}],"collection":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex"}],"about":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/types\/codex"}],"author":[{"embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/comments?post=2575"}],"version-history":[{"count":7,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex\/2575\/revisions"}],"predecessor-version":[{"id":2866,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex\/2575\/revisions\/2866"}],"wp:attachment":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/media?parent=2575"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/tags?post=2575"},{"taxonomy":"codex-type","embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex-type?post=2575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}