@jarvis It work well, here is the modified code below…
<?php
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged,
'fields' => 'ids'
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) :
while ($wp_query->have_posts()) : $wp_query->the_post();
$pdf_upload = get_field('pdf_upload');
if( $pdf_upload ): ?>
<li> <a href="<?php echo $pdf_upload['url']; ?>"><? echo $product->post->post_title; ?></a></li>
<?php echo '<span class="date_published">Published on: ' . get_the_date('Y', $product->get_id()) . '</span>'; ?>
<?php endif;
endwhile;
endif;
?>
@hube2 The page is indeed pretty slow, I will work on the Ajax now, I will keep this thread updated with the code.
Thanks

If you can setup a field, then you can do something like:
<?php $image = get_field('image');
if( !empty( $image ) ): ?>
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
<?php endif; ?>
You would need to change the field name from image to whatever you need.
Or you could do something like:
<?php $image = get_field('image');
if( !empty( $image ) ): ?>
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
<?php else: ?>
<img src="url-to-placeholder" class="placeholder-class" ?>
<?php endif; ?>
That way you don’t need the jQuery, as it checks if an image exists/been added if not, uses a fall back to a placeholder image

Hi @teegee
If the placeholder can have a class, then perhaps look to use jQuery:
$(".class").show();
$(".class").hide();

Hi @danis44
Yes, only works if a pdf has been added, so add a pdf just to check the code works.
echo '<a href="'.$pdf['url'].'" class="your-class-name" target="_blank">link</a>';
Update to this line for a class and opening in a new tab. Just change the class to what you need, then add styling via CSS

You can use add_filter( 'get_image_tag_class', '__return_empty_string' );
To remove all classes
You can also use
add_filter('get_image_tag_class','add_custom_image_class');
function add_custom_image_class($class){
$class .= ' news__img';
return $class;
}
To add new classes. This only works when adding images after the code is in place not to existing images.
Alternatively, you could look to use jQuery and do a find/replace on the class

As a quick after thought, you *may* need to access the product ID to get the data from the field, if so, try:
add_action( 'woocommerce_before_add_to_cart_form', 'my_pdf_field' );
function my_pdf_field() {
global $product;
$product_id = $product->get_id();
$pdf = get_field( 'pdf', $product_id );
#if we have data, show it
if( $pdf ){
echo '<a href="'.$pdf['url'].'">link</a>';
}
}

Hi @danis44
You can try something like:
add_action( 'woocommerce_before_add_to_cart_form', 'my_pdf_field' );
function my_pdf_field() {
$pdf = get_field( 'pdf' );
#if we have data, show it
if( $pdf ){
echo '<a href="'.$pdf['url'].'">link</a>';
}
}
I’ve assumed the PDF field you’ve added is called pdf, it’s a file type and returns an array (not a URL)
Code is untested and goes in your functions.php file

Does something like the below work:
add_action( 'woocommerce_after_main_content', 'my_extra_description' );
function my_extra_description() {
global $wp_query;
# get the query object
$category = $wp_query->get_queried_object();
#get the cat ID
$category_ID = $category->term_id;
#get the field
$extra_description = get_field( 'extra_description', 'category_'.$category_ID );
#if we have data, show it
if( $extra_description ){
echo $extra_description;
}
}
Code untested and goes in your functions file

Hi @olympesmn
If you need it on all pages, you don’t need to add the ACF field to a Gutenberg block.
So add the ACF field and under rules, set the post type to page (assuming it’s pages you need it on).
In your code, you then call the field like a normal ACF field
So something like:
<div style="background-color:<?php the_field('background_color'); ?>">
</div>

Hi @avearthasz
You would need to add a function to the theme’s function file, something like:
add_filter( 'post_thumbnail_html', 'remove_media_attributes', 10 );
add_filter( 'image_send_to_editor', 'remove_media_attributes', 10 );
function remove_media_attributes( $html ) {
$html = preg_replace( '/(width|height|class)="\d*"\s/', "", $html );
return $html;
}
Code untested!

You could try something like the below:
<?php
$original_date = "20211019";
// Creating timestamp from given date
$timestamp = strtotime($original_date);
// Creating new date format from that timestamp
$new_date = date("d-m-Y", $timestamp);
echo $new_date; // Outputs: 19-10-2021
?>
New project with only the ACF plugin (PRO) installed (5.10.2).
I put this inside functions.php (generated by ACF and then modified to use the field key inside the conditional_logic array) :
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_616de148bf2ce',
'title' => 'page after title',
'fields' => array(
array(
'key' => 'field_616de15b4155f',
'label' => 'Field in after-title group',
'name' => 'test',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'page',
),
),
),
'menu_order' => 0,
'position' => 'acf_after_title',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
acf_add_local_field_group(array(
'key' => 'group_616de1da31d45',
'title' => 'page normal',
'fields' => array(
array(
'key' => 'field_616de1eb45ead',
'label' => 'Field in normal group',
'name' => 'hiding',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => [
[
[
'field' => 'field_616de15b4155f',
'operator' => '!=',
'value' => 'test'
]
]
],
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'page',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
I can see both fields on the page, but when I type “test” into the first one (inside the after-title group), nothing happens (the second field inside the normal group should disappear).
BTW : thank you for your time ! It is really appreciated
Alright I’ll try that, I didn’t know there was a prerequisite like that, I shipped about 20 projects without those prefixes and never had any issue (never tried to do conditions across field-groups though).
I’ll let you know, thank you !
Oh ok sorry, those actually are field keys, I’m setting them programmatically when defining the fields by code. They are unique in the context of the post-type.

field keys are required for conditional logic
OK, have located the ACF group inputs. They have somehow moved to the right sidebar where all the usual page settings are – Publish, Featured image etc.
How on earth did that happen? And how can I get them back in the main page edit area?
Some of the fields require a lot of input text, it will be almost impossible for the client to use them in that location.
Skip this question…I found my issue. I didn’t realize in another portion of the template there was a different WP Query. The variable was pulling from the wrong content.

This solved my issue: https://code.tutsplus.com/tutorials/show-wordpress-related-posts-with-taxonomy-and-a-custom-post-type–cms-32303
$productterms = get_the_terms( get_the_ID(), 'listing_location' );
if( $productterms ) {
$producttermnames[] = 0;
foreach( $productterms as $productterm ) {
$producttermnames[] = $productterm->name;
}
}
$args = array (
'post_type' => 'post_type_listings',
'tax_query' => array(
array(
'taxonomy' => 'listing_location',
'field' => 'slug',
'terms' => $producttermnames,
),
),
);
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ): ?>
<section class="product-related-posts">
<?php echo '<h2>' . __( 'Related Posts', 'tutsplus' ) . '</h2>'; ?>
<ul class="product-posts">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
</section>
<?php endif;
};

I have not had to enable this on any site. WP automatically adds lazy loading to images that are inserted into WP content areas, it automatcially adds the attribute unless you tell it not to.
lazy loading by adding loading="lazy" to image tags is not a WP thing. This is a browser thing. Browsers not recognize this attribute. In WP is just means that WP is not added the attribute automatically when it generates an image tag.
Sorry, it does not work for me…
I have exactly the same need than @peterpans
I created the this rule: Taxonomy is equal Category (product_cat), then I am able to provide some content for each product category. But when I try to add some php code to display it, I have no good result, as I am not a developer and tutorials I found are not detailed enough…

You just need to add loading="lazy"
I want to add to this that the minimum required fields in the flexible layout fields also doesn’t work.
Currently only found the bug in the following layout, haven’t tested much further:
Block > Repeater > Flexible layout with min. fields of 2
Hello everybody
I had the same question. Do I have to add this code into the woocommerce/archive-product.php file? If so, between which lines?
Thank you for your help.
Thank you, the acf_update_setting mentioned in that thread was a help,
With acf_update_setting I was able to get rid of select2, datepicker, timepicker
Then after much searching and help from Query Monitor, I was able to get the handles and figure out alot of the others need to be dequeued through init hook, so through that I was able to get rid of jq touch punch, iris, wp-color-picker and code-editor.
Through the init you can also get rid of jq ui core, jq ui mouse, jq ui sortable & jq ui resizable – unfortuneatly due to how they are all dependencies of each other and other scripts are dependencies/dependants of them, they seem to end up causing errors and breaking things with the main acf js object.
Would be great if there was a way for these not all to be so intertwined however I understand why its like this, it just makes simple text field based forms somewhat pointless in acf_form when compared to other options.
FYI for anyone in the future: I did have to also deregister & dequeue

The only other thing that I can think or is that you have some type of filter, possible a pre_get_posts filter that is interfering with the query. Could be in a plugin or the theme.
Have you considered creating a bidirectional relationship field?
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.