
Try changing tax_name to your actual taxonomy, does that work?

Hmm, something like:
<?php
$now = time();
$date_created = $order->get_date_created();
$dt = new DateTime($date_created);
$date = $dt->format('Y-m-d');
$your_date = strtotime($date);
$datediff = $now - $your_date;
$diff = round($datediff / (60 * 60 * 24));
update_post_meta( $post_id, 'custom_field', $diff );
Amend custom_field to your field name, code untested

Hi,
The repeater field would be great for this.

Would the get field not need the taxonomy name? As per the docs
For example:
$summaryimage = get_field('summary_preview_image', 'tax_name_'.$termid);
Assuming the image is assigned to the taxonomy.

You would need to use PHP’s date_diff
Grabbing the date from the order and todays date.
Once you have the value, you can use update_post_meta() to pass the value to your post

Typo in the above, in the functions part, change:
if( $sector ) {
$terms = get_terms( $genre );
$genre_id = wp_list_pluck( $terms, 'term_id' );
}
To:
if( $genre ) {
$terms = get_terms( $genre );
$genre_id = wp_list_pluck( $terms, 'term_id' );
}

Ok, so one thing I think you need to do, is change your function (my_pre_get_posts).
As a checkbox returns a serialised array, I believe you need to change the compare from IN to LIKE (worth double checking!):
// append meta query
$meta_query = [];
$meta_query[] = array(
'key' => 'film_genre',
'value' => $_GET['film_genre'],
'compare' => 'LIKE',
);
Now, the next point to consider is returning ACF fields. Usually, if you want to get a value, you can simply use get_field.
If you want to get the value from a specific page/post you can add in the ID (more examples can be seen here).
The issue I think you have is that you’ve assigned the ACF fields to a custom post type and output them on an archive template (archive-film.php).
As such, for whatever reason, when you move to the result, it doesn’t show the ACF field.
You then can’t specify an ID against the get_field as an archive doesn’t have an ID value.
I’ve played around with code locally but can’t seem to get it working either – unless I’m missing something.
If it were me, I think I’d approach it differently.
I’d use the films custom post type
I would then use the film genre as a taxonomy
I’d create a page called films and have a dedicated template (page-films.php for example).
It would be far easier to query and you could also look to use AJAX.
Something like the below. page-films.php
<?php
/**
* @package WordPress
Template Name: Films
**/
get_header();
?>
<div class="container-fluid" id="filters">
<div class="row">
<div class="col-12 py-0">
<nav class="navbar navbar-expand-md navbar-fixed-top navbar-light main-nav pt-5 pb-4">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarFilters" aria-controls="navbarFilters" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarFilters">
<?php if( $genres = get_terms( array( 'taxonomy' => 'genres' ) ) ) : ?>
<ul class="nav navbar-nav order-1 order-md-2">
<li class="nav-item active">
<a class="reset btn btn-red-outline mr-2 mb-4" href="#" sector="genre" genreid="">All</a>
</li>
<?php
foreach( $genres as $genre ) : ?>
<li class="nav-item">
<a class="btn btn-red-outline mr-2 mb-4" href="#" genre="" genreid="<?php echo $genre->term_id; ?>"><?php echo $genre->name; ?></a>
</li>
<?php endforeach;
echo '</ul>';
endif;
?>
</div><!-- /navbarFilters -->
</div>
</nav>
</div><!-- /col-12 -->
</div><!-- /row -->
</div><!-- /container -->
<?php
global $wp_query;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 12,
'post_type' => 'films',
'paged' => $paged
);
$wp_query = new WP_Query($args); ?>
<?php if ($wp_query->have_posts()) : ?>
<section class="container py-0">
<div class="row" id="ajax_filter_films">
<p class="filter_status"></p>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); $col = 'col-md-4'; ?>
<?php include( locate_template( 'includes/loop.php', false, false ) ); ?>
<?php endwhile; ?>
</div><!-- /row -->
<div class="row pt-3 pb-5" id="pagination">
<div class="col-12 col-md-8 offset-md-2">
<div align="center"><?php wpbeginner_numeric_posts_nav(); ?></div>
</div><!-- /col-md-8 -->
</div><!-- /row -->
</section><!-- /container -->
<?php endif; wp_reset_query(); ?>
<?php
get_footer();
loop.php would contain whatever you need, like the post title, image and any other info.
Then in your footer (or enqueue it), add the javaScript:
<script>
//filter the films
jQuery(function($){
$('#filters .btn').click(function(){
var genre = jQuery(this).attr("genre");
var genreid = jQuery(this).attr("genreid");
$.ajax({
type : "POST",
data : { action : 'get_film_posts', genre: genre, genreid: genreid },
dataType : "html",
url : '<?php echo admin_url('admin-ajax.php');?>',
success : function(data) {
//alert(this.data);
jQuery("#ajax_filter_films").html(data);
},
error : function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
return false;
});
});
</script>
Finally, in your functions file:
<?php
function get_film_posts() {
$genre_id = $_POST['genreid'];
$genre = $_POST['genre'];
if( $sector ) {
$terms = get_terms( $genre );
$genre_id = wp_list_pluck( $terms, 'term_id' );
}
$args = array(
'post_type' => 'films',
'post_status' => 'publish',
'posts_per_page' => -1, // show all posts.
'order' => 'DESC',
);
$args['tax_query'] = array(
'relation' => 'OR',
array(
'taxonomy' => 'genres',
'field' => 'term_id',
'terms' => $genre_id
),
);
$query = new WP_Query( $args );
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post(); $col = 'col-md-4';
include( locate_template( 'includes/loop.php', false, false ) );
endwhile; wp_reset_postdata();
endif;
die();
}
// Fire AJAX action for both logged in and non-logged in users
add_action('wp_ajax_get_film_posts', 'get_film_posts');
add_action('wp_ajax_nopriv_get_film_posts', 'get_film_posts');
That should then get you somewhere!

So you don’t want to update the Woo product info but 2 different custom post types.
But you want that to happen when you publish a woo product or have I misunderstood?
My concern is how you get the post ID of both CTPs at the same time. The only way around this would be that both CPTs have an identifier.
When you then run the update, you would need to query both post types for posts with that identifier, this would return the post IDs. You can then update those posts with whatever you need.

Have you tried using a True/False field? It may be far easier to toggle you the value of 1 or 0

Does this post do what you need?
Once you query but what you need, you can then do something like:
$the_query = new WP_Query( $args );
$totalposts = $the_query->found_posts;
echo $totalposts;
Code untested and will need adjusting to fit your field names etc. but should get you underway!

No, you should be able to enable view field keys. This will show when your on the add/edit fields screen.
Then click to edit your repeater field and it should then show the subfield keys

Yep
So you can use the gform_after_submission as is or you can be more specific with the form ID:
Applies to all forms.
add_action( 'gform_after_submission', 'after_submission', 10, 2 );
Applies to a specific form. In this case, form id 5.
add_action( 'gform_after_submission_5', 'after_submission', 10, 2 );
Change the 1 in the below to your Gravity Form field ID:
$number_of_posts = rgar( $entry, '1' );
Then switch the field key IDs:
#add the row to the repeater
$row = array(
'field_5d9470467aab9' => $number_of_posts #this is your repeater subfield key
);
$i = add_row('field_5d946796a4fd7', $row, $post_id->ID); #this is the main repeater key
Without knowing the full ins and outs of your setup, that should help get you underway!
You may need to tweak accordingly but fingers crossed!

I believe you need to look at the gform_after_submission hook.
You then use Gravity Forms rgar value.
Perhaps, you could use repeater field and add the oEmbed field into that?
<?php
add_action( 'gform_after_submission', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
//getting post
$post = get_post( $entry['post_id'] );
//change the 4 to your gravity form field number
$number_of_posts = rgar( $entry, '1' );
#add the row to the repeater
$row = array(
'field_5d9470467aab9' => $number_of_posts #this is your repeater subfield key
);
$i = add_row('field_5d946796a4fd7', $row, $post_id->ID); #this is the main repeater key
}
Just an idea. You may need to play around with the concept!

Glad the images are sorted.
Ok, add this to your function file:
<?php
function which_template_is_loaded() {
global $template;
print_r( $template );
}
add_action( 'wp_footer', 'which_template_is_loaded' );
Now go to the main films page, it will tell you the template, run the filter, is it the same template?
As I say, I wonder if the results page isn’t the same page, so the filters don’t show. The reason being where you assigned the ACF filters to (if that makes sense)

Does the following work:
<?php
$args = array(
'post_type' => 'event',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
'date_clause' => array(
'key' => 'event_start_date',
'value' => $today,
'type' => 'DATE',
'compare' => '>='
),
),
'orderby' => array(
'date_clause' => 'ASC',
),
);
Code untested

si vous utilisez l’outil de journalisation/d’inspection de la console, voyez-vous des erreurs ? J’ai récemment eu un problème avec un carrousel et j’ai trouvé que l’appel CDN pour jQuery ne fonctionnait plus, ce qui a cassé la plupart de mon site en conséquence.

Apologies – that makes sense.
So <?php $test = get_field('header-achtergrond'); echo $test; ?> returns nothing.
Where should the get_field pull data from, is it the page/post your own or an options page or somewhere different?
If its the post, can you add the post ID in question into the get_field request for $test? Does that work?

Can you remove the html before and after <!– is used to comment out, which may explain seeing nothing

What does: $test = get_field('header-achtergrond'); echo $test; output?
Assume the field has a value? Is it in a loop or does it need a page/post ID?
Does your conditional code get triggered?
`if(get_field(‘header-achtergrond’) == “image”):
echo ‘hello, we get this far!’;
endif;

Can you share your solution? It may help others going forward.

I suggest you look at do_action( ‘user_register’, int $user_id, array $userdata )
Which fires immediately after a new user is registered.
So as an example (code untested), you could look at something like:
<?php
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
####generate the random number
#get current date/time
$date = date('YmdH:i:s');
#randmoise
$randomise = ($date * 25);
update_user_meta($user_id, 'your_acf_field_name', $randomise );
}
You need to setup the ACF field and link it to the user role(s). You then need to update the above example with the field name.
Add the code to your function file and test it.
If it doesn’t work, look to try and debug why.

it worked great before online, i had integrated a product carousel through elementor except 2 weeks ago, i thought it was from the update so i went back to my site to the previous acf version and elementor it 2 weeks ago, that doesn’t change the problem
I am actually in 7.4 in PHP on the local and in 7.3 online with OVH, I went to 7.4 on OVH but nothing helped.
I tried to recreate a Template just in case but nothing helps.
If your local version works, can you not upload a copy of that to your hosting server? Ensure PHP version matches and see if that works.
Si votre version locale fonctionne, ne pouvez-vous pas en télécharger une copie sur votre serveur d’hébergement ? Assurez-vous que la version PHP correspond et voyez si cela fonctionne.

I have encountered a problem for 2 weeks, I have a Template with ACF fields but as soon as I modify this Template to add things with elementor, the ACF fields no longer want to be displayed in front although in BO I do not have no worries
I have no problem with this on my local site
If this doesn’t happen on your local site, I would imagine its a server setting. Does your hosting server run a different version of WordPress, Elementor, PHP?
Si cela ne se produit pas sur votre site local, j’imagine que c’est un paramètre de serveur. Votre serveur d’hébergement exécute-t-il une version différente de WordPress, Elementor, PHP ?

Nice one and thanks for the update. I needed a custom API due to requiring specific info but glad you found a solution too.

I think I had similar but found you can alter the API output. For me, I needed to customise the API response for WooCommerce, here’s the code I used which may help:
// Custom API Data
function product_compact_post( $data, $post, $request ) {
$categories = get_the_term_list( $data->data['id'], 'product_cat' );
$categories = strip_tags( $categories );
$product = wc_get_product( $data->data['id'] );
$image_id = $product->get_image_id();
$image_url = wp_get_attachment_image_url( $image_id, 'full' );
$brands = get_the_term_list( $data->data['id'], 'product_brand' );
$brands = strip_tags( $brands );
$model = get_field('model', $data->data['id']);
$sku = str_replace( array(' ', '&', '/'), array('_', '', ''), $model );
return [
'id' => $data->data['id'],
'sku' => $data->sku = $sku,
'name' => $data->data['title']['rendered'],
'link' => $data->data['link'],
'categories'=> $data->categories = $categories,
'image' => $data->image = $image_url,
'manufacturer' => $data->manufacturer = $brands,
'model' => $data->model = $model,
'mpn' => $data->mpn = $model,
'ean' => $data->ean = get_field('ean', $data->data['id'])
];
return $data;
}
add_filter( 'rest_prepare_product', 'product_compact_post', 10, 3 );
You may be able to edit for your needs.
Hope that helps!
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.