If the gallery is for a user, you need to change the get_field for the gallery to include the user ID:
$images = get_field('galleria_partner', 'user_'. $author_id);
This assumes you have access to $author_id!?
As for showing info on different rows, that’s just HTML and entirely up to you.
Before you do the update_field. If you output $value, does it return anything?
Have you tried adding the post ID to the update_field to see if that works?
update_field($field_key, $value, $element->ID);
I assume the closing tag for the foreach isn’t included in the above code?
You’re adding another form to the page, hence why you’re having issues. You just need to amend the existing woo review form
If you want to add the fields to the existing Woo Reviews form, when you create the ACF fields , under Rules set the field group to Comments (under the form heading) is equal to then select Product.
Testing this on a fresh install of WP, Woo and the 21 theme, the new fields show on the product review forms.
I have a feeling its due to how the data is inserted. Something in my head tells me that you need change the priority on the save post function when inserting data from an import.
I assume the post is created when you import from your XLS?
What does your function look like to import and add the ACF fields?
Check the docs as I think you need to amend the priority on the function. You may need to use the field key rather than the field name but think its the priority.
Adding to a repeater is slightly different to updating a field. Check the docs
Basically, when you loop through your API data (foreach), you need to use something like:
$row = array(
'image' => 123,
'alt' => 'Another great sunset',
'link' => 'http://website.com'
);
add_row('images', $row);
Just amend the fields to suit your needs.
Is the same template used, can you edit it or create a child theme? Perhaps contact the theme developer?
I know it may not help but can you bulk edit say 100 at a time? Don’t make changes, just select bulk edit, check all then click update. Should resave the post without changes but may reconnect the data. Worth a try
When you run the import, it creates the posts and adds your data.
Just check out WP all import as I’m sure it has a demo video
I suspect you will need a custom template or to alter the existing template. It sounds like the ACF fields are outside the password protection code – hence the issue.
Not knowing the setup. You could either:
1) Use the inbuilt password protection within WP and hope your theme caters for this OR
2) You need to create a custom template:
<?php
/**
* Template Name: Password-Protected Custom Template
*/
?>
<?php get_header(); ?>
<div class="entry-content">
<?php
// STARTS - wrapp your content with this conditional statement
if ( post_password_required() ) :
// if your post is password protected with our Pro version, show our password form instead
echo get_the_password_form();
/* display the password protected content if the correct password is entered */
else :
// display any custom private content
echo 'custom HTML content';
// fetch & print WordPress custom field value via get_post_meta calls
$custom_field_content = get_post_meta( $post->ID, 'key_1', true );
echo $custom_field_content;
// fetch & print ACF fields
the_field( 'acf_introduction_text' );
endif;
// ENDS - hide custom fields with PPWP password protection
?>
</div>
<?php get_footer();?>
You can then assign the template to your page and set the password.
You need to loop the taxonomies and in doing so, get the taxonomy ID
Once you have that, you can access the custom fields you store against the taxonomy.
Something like:
<?php if( $contacts = get_terms( array( 'taxonomy' => 'contact' ) ) ) :
foreach( $contacts as $contact ) :
$email_du_contact = get_field('email_du_contact', 'term_' .$contact->term_id );?>
<?php echo $email_du_contact; ?>
<?php endforeach;
endif;
?>
Code untested
Are you wrapping your ACF fields inside the password protected area?
Perhaps you could show your code so we can help?
You could look at WP All Import, whilst its a premium plugin, it makes life easier.
Basically, you upload your file, specify the post type (pages, posts, custom posts), map the CSV columns to your ACF fields and import.
It then creates all the new posts with the data.
This looks like a repeater, are you using the user ID in the if and while part of the repeater call?
Is the field set to return an array or URL?
But I think the issue is this:
<img src="<?php echo esc_attr($nomInfo['user_avatar']); ?>" alt="author-avatar" />
Should be this:
<img src="<?php echo esc_url($nomInfo['url']); ?>" alt="<?php echo esc_attr($nomInfo['alt']); ?>" />
Is the staging site identical to the live site? So if you’re using get_field and it has a page/post ID, it’s the same in both environments?
Do other fields work on other pages? Are you able to share your code for others to look?
Have you flushed the cache within the Siteground account? Not just at the WordPress level? I think I once had similar and had to do a master flush (or whatever it’s called).
Previously, I’ve added some code to my functions file:
// Create custom query for API
if( ! function_exists( 'product_meta_request_params' ) ) :
function product_meta_request_params( $args, $request ){
$args += array(
'meta_key' => $request['meta_key'],
'meta_value' => $request['meta_value'],
'meta_query' => $request['meta_query'] == 1 ? array(
array(
"key" => "model",
"value" => array(''),
"compare" => 'NOT IN',
)
) : $request['meta_query']
);
return $args;
}
add_filter( 'rest_product_query', 'product_meta_request_params', 99, 2 );
endif;
My API URL then looked like:
https://www.domain.com/wp-json/wp/v2/product/?page=' . $current_page . '&per_page=10&meta_query=1
Worth looking at this forum post it may help you
It depends what the repeater currently includes and how you need to use the repeater fields in the new posts as to how you map the data!
Does the newly created post not have a repeater and all existing repeater fields go to new custom fields for example?
If so, you can use update_post_meta()
foreach ($items as $item_key => item) {
Should be:
foreach ($items as $item_key => $item) {
Whoa, that’s a pretty mammoth task!
My approach would be to make use of the API and batch processing.
The idea being that it can work through without (in theory) timing out.
You would need to handle that for each custom post type. I assume it’s the same repeater for each post type?
As a possible starting point, perhaps something like the below:
<?php
add_action( 'wp_ajax_nopriv_get_batch_posts_from_api', 'get_batch_posts_from_api' );
add_action( 'wp_ajax_get_batch_posts_from_api', 'get_batch_posts_from_api' );
function get_batch_posts_from_api() {
$current_page = ( ! empty( $_POST['current_page'] ) ) ? $_POST['current_page'] : 1;
// create a file to test the output (this will be the same dir as your functions file if you add this code to functions.php)
$page_report = get_stylesheet_directory() . '/page_report_'.date("dmY").'.txt';
$data = 'Current Page: '.$current_page;
file_put_contents( $page_report, $data . "\n", FILE_APPEND ); // useful to debug
// Create an array
$posts = [];
// $results return an array of objects - CHANGE /posts/ to your custom post type
// Go to the URL https://www.domain.com/wp-json/wp/v2/posts/ to check it shows posts (amend URL accordingly)
$results = wp_remote_retrieve_body( wp_remote_get('https://www.domain.com/wp-json/wp/v2/posts/?page=' . $current_page . '&per_page=10') );
// convert JSON string to PHP array
$results = json_decode( $results );
// either the API is unavailable or we have an error, so bail
if( ! is_array( $results ) || empty( $results ) ){
return false;
}
$posts[] = $results;
foreach( $posts[0] as $post ){
if( have_rows('repeater_field_name', $post->id) ):
while( have_rows('repeater_field_name', $post->id) ) : the_row();
$sub_value_1 = get_sub_field('sub_field_1');
$sub_value_2 = get_sub_field('sub_field_2');
// Create post object
$post_title = wp_strip_all_tags( $sub_value_1 );
$new_post = array(
'post_title' => $post_title,
'post_content' => $sub_value_2,
'post_status' => 'publish',
'post_author' => 1,
);
// Insert the post into the database
$post_id = post_exists( $post_title ) or wp_insert_post( $new_post );
endwhile;
endif;
}
// browse to the URL to trigger this script
// https://www.domain.com/wp-admin/admin-ajax.php?action=get_batch_posts_from_api
$current_page = $current_page + 1;
wp_remote_post( admin_url('admin-ajax.php?action=get_batch_posts_from_api'), [
'blocking' => false,
'sslverify' => false, // we are sending this to ourselves, so trust it.
'body' => [
'current_page' => $current_page
]
]);
}
The code works for batch processing but clearly not tested for your needs! So may require tinkering.
I assume the CPT is accessible via the API (check by browsing to the API URL).
I also assume the repeater is the same in each post
Finally, you would need to map the repeater fields to the new post fields.
Hope that helps!
I’m not familiar with Elementor but have a feeling you need an add-on for certain fields (I could be wrong).
Worth checking this tutorial on using repeater fields.
May help!
If an ACF field can be used to set a featured image, can’t you simply use the same field names.
So if someone adds to the featured image, does it not add to the ACF field? Not tried it but in theory, should be the same function.
I believe you need the field as an image with the label of post_image.
Possibly more to it, I don’t know.
You may need to reverse the following code:
add_action('acf/save_post', function ($post_id) {
$value = get_field('post_image', $post_id);
if ($value) {
if (!is_numeric($value)) {
$value = $value['ID'];
}
update_post_meta($post_id, '_thumbnail_id', $value);
} else {
delete_post_meta($post_id, '_thumbnail_id');
}
}, 11);
But get the featured post ID using get_post_thumbnail_id then pass the value/details back to your ACF field
The checkboxes on the film page will only be shown if a film is assigned, so it prevents someone clicking filters and having no results.
The code is in place as fallback OR in case you wish to adjust this behaviour.
With regards to the similar/related films on the single film page, it depends on whether a film is assigned to one or many categories?
Basically, you get the genres associated to the film you’re on, you can then run a query on the film post type and loop the results, something like:
<?php
$genres = get_the_terms( $post->ID, 'genres' );
$genre = $genres[0];
// print object from first genre
#print_r($genre);
// or get the genre name
#echo $genre->name.' '.$genre->term_id;
global $wp_query;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 3,
'post_type' => 'film',
'paged' => $paged,
'fields' => 'ids',
'post__not_in' => array( $post->ID )
);
if($genre):
$args['tax_query'] = array (
'relation' => 'OR',
array(
'taxonomy' => 'genres',
'field' => 'term_id',
'terms' => $genre->term_id
),
);
endif;
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) :
?>
<h3>Similar Films</h3>
<ul>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; wp_reset_query(); ?>
So basically, it you have multiples, it gets the first taxonomy only. You can of course adjust this but should help you out
Hi @planbjz
I had a similar issue before and came across this gem Programmatically Add Images to Media Library
May need a little tweaking but certainly worked for my needs.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.