Fixed by using get_the_ID()
instead of $post_id
Thanks for your time bro 😉
Thank you for your reply,
the $post_id
is returning a numeric value like “3243”.
if you have any other idea i’ll be happy to hear that my friend 😉
Thanks a lot @hube2 , i can now can upload images from external url and add them all to ACF Gallery.
still there is one more problem.
i’m using these line of codes:
// Set Fetched ArtWork as Post Thumbnail
$DownloadArtWork_Importer = media_sideload_image( $data['download_artwork'], $post_id, null, 'id' );
set_post_thumbnail( $post_id, $DownloadArtWork_Importer );
// Set Fetched ScreenShots as Post Gallery
$DownloadScreenShot_Importer = array($data['download_screenshots']);
foreach($DownloadScreenShots as $DownloadScreenShot) {
$DownloadScreenShot_Importer[] = media_sideload_image( $DownloadScreenShot, $post_id, NULL, 'id');
}
update_field( 'field_5d94fb71cf60f', $DownloadScreenShot_Importer , $post_id );
the ArtWork image (thumbnail) is attached to current post but screenshots (Gallery images) are not attached to wp post.
see screenshot below please:
i know it’s probably from WP not ACF but i’ll appreciate it if you can give me hint on how can i attach gallery images to wp post just like thumbnail …
Thanks a lot, i can now can upload images from external url and add them all to ACF Gallery.
still there is one more problem.
i’m using these line of codes:
// Set Fetched ArtWork as Post Thumbnail
$DownloadArtWork_Importer = media_sideload_image( $data[‘download_artwork’], $post_id, null, ‘id’ );
set_post_thumbnail( $post_id, $DownloadArtWork_Importer );
// Set Fetched ScreenShots as Post Gallery
$DownloadScreenShot_Importer = array($data[‘download_screenshots’]);
foreach($DownloadScreenShots as $DownloadScreenShot) {
$DownloadScreenShot_Importer[] = media_sideload_image( $DownloadScreenShot, $post_id, NULL, ‘id’);
}
update_field( ‘field_5d94fb71cf60f’, $DownloadScreenShot_Importer , $post_id );
the ArtWork image (thumbnail) is attached to current post but screenshots (Gallery images) are not attached to wp post.
see screenshot below please:
i know it’s probably from WP not ACF but i’ll appreciate it if you can give me hint on how can i attach gallery images to wp post just like thumbnail …
Thanks a lot, i can now can upload images from external url and add them all to ACF Gallery.
still there is one more problem.
i’m using these line of codes:
// Set Fetched ArtWork as Post Thumbnail
$DownloadArtWork_Importer = media_sideload_image( $data['download_artwork'], $post_id, null, 'id' );
set_post_thumbnail( $post_id, $DownloadArtWork_Importer );
// Set Fetched ScreenShots as Post Gallery
$DownloadScreenShot_Importer = array($data['download_screenshots']);
foreach($DownloadScreenShots as $DownloadScreenShot) {
$DownloadScreenShot_Importer[] = media_sideload_image( $DownloadScreenShot, $post_id, NULL, 'id');
}
update_field( 'field_5d94fb71cf60f', $DownloadScreenShot_Importer , $post_id );
the ArtWork image (thumbnail) is attached to current post but screenshots (Gallery images) are not attached to wp post.
see screenshot below please:
i know it’s probably from WP not ACF but i’ll appreciate it if you can give me hint on how can i attach gallery images to wp post just like thumbnail …
Thanks for your reply,
i think we have make a progress but there is some major problems.
1. when i add a test taxonomy term and i select a post from ACF relationship field upon adding the taxonomy term a new taxonomy term with a number is being created beside the one i was adding and the selected post (inside ACF relation field) are being attached to that taxonomy term (number) not the one i want to create (please see the screenshot attached, “test” is what i was making and “173” is the one that is created automatically. )
2. when i open a taxonomy term that has a post attached to itself ACF relation field is empty i want the relationship field to be live and i want to manage posts of a taxonomy term just by ACF relationship (instead of editing the posts one by one. )
P.S: my taxonomy name is list, and my taxonomy and my post type are attached. i’ve double checked these.
in general by using this code:
function Taxonomy_List_Save( $post_id ) {
$posts = get_field('downloads_listing', $post_id);
$term_id = intval(str_replace('term_', $post_id));
if ($posts) {
foreach ($posts as $post) {
// make sure "list" is the taxonomy name and not the term name
wp_set_post_terms($post->ID, $term_id, 'list', true);
}
}
}
add_action('acf/save_post', 'Taxonomy_List_Save', 15);
in my functions.php i should be able to edit a taxonomy term (like tags) and select a post from “RelationField” of acf and by saving the tag term page the selected post should have that tag attached automatically ?
cause this is what i’m looking for and neither by term id or slug i can’t make it work with the above code.
any other idea ?!
That line already is my Taxonomy Slug Bro,
name: list
label: Lists
singular_label: List
description: ""
public: true
publicly_queryable: true
hierarchical: false
show_ui: true
show_in_menu: true
show_in_nav_menus: true
query_var: true
query_var_slug: ""
rewrite: true
rewrite_slug: ""
rewrite_withfront: true
rewrite_hierarchical: false
show_admin_column: true
show_in_rest: true
show_in_quick_edit: true
rest_base: ""
rest_controller_class: ""
meta_box_cb: ""
i really appreciate your replies @hube2,
but the code is not functional no matter what i try,
i have a taxonomy(Tag Like) named: Download List
i have a term inside “Download List” named: New Apps
i have a post named : FirstApp
now WHAT i need is a function:
To add “NewApps” as a term of “Download List” Taxonomy, INSIDE “FirstApp” Post.
When i open the edit page of “New Apps” (Taxonomy Term)
and select “FirstApp” from acf relation field and update the taxonomy term.
Believe me i’m searching any trying so hard to complete this function but still got no luck.
i really really appreciate it if you can help me make this done.
Thanks @hube2 for your reply,
but the code is not adding taxonomy term on post.
i think we have to define two things
1. limit this function to taxonomy “List Only”
2. load the posts inside Taxonomy Term’s relation fields then add the current taxonomy term into “all posts selected with taxonomy term’s relation field”
but the code i added is not doing anything actually … 🙁
hi @mrkeithy,
Would you please take a look at this topic please?
https://support.advancedcustomfields.com/forums/topic/update-taxonomy-of-posts-selected-by-acf-relation-field/#post-123227
i’m not sure what i’m missing i appreciate it if you could give me a hint.
i’ve searched a bit and extend my code to this:
function Taxonomy_List_Save( $post_id ) {
if is_tax( 'list' ) {
$PostList = get_field('downloads_listing', $post_id);
if( $PostList ) {
foreach( $PostList as $post) {
setup_postdata($post);
wp_set_post_terms( $post_id, 'TaxonomyTermName', 'list', true );
}
wp_reset_postdata();
}
}
}
add_action('acf/save_post', 'Taxonomy_List_Save', 15);
can you fix the code for me please? or give me hint on what’s missing ?
Thanks a bunch John,
can you please help me with the code ?!
function Taxonomy_List_Save( $post_id ) {
$PostList = get_field('downloads_listing', $post_id);
if( $PostList ):
foreach( $PostList as $List): // variable must be called $post (IMPORTANT)
wp_set_post_terms( $post_id, $PostList->ID, 'list', true );
endforeach;
endif;
// Check if a specific value was sent.
if( get_field('hero_image', $post_id) ) {
// ...
}
}
add_action('acf/save_post', 'Taxonomy_List_Save', 15);
P.S: Pardon my bad coding skill… 🙁
any news guys ?
any help guys ?!
thanks
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.