Well..
I think you need to use other function. https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/
Something like this:
<img src="<?php echo get_the_post_thumbnail_url( $location->ID, 'thumbnail' ) ?>" />
This should work with something like:
$args = array(
'post_type' => 'your_custom_post_type',
'meta_key'=> 'your_field_date',
'orderby' => 'meta_value',
'order' => 'ASC'
);
If you’re are working with the archive page, maybe a best way to do it is modify the main query with the pre_get_posts
hook.
For Example:
// in your functions.php
function sort_by_date_my_cpt( $query ) {
if ( is_post_type_archive( 'your_custom_post_type') ) {
$query->set('meta_key', 'your_date_custom_field');
$query->set('orderby', 'meta_value');
$query->set('order', 'ASC');
return;
}
}
add_filter( 'pre_get_posts', 'sort_by_date_my_cpt', 1);
So then, you will to use your WP Loop by default in your archive template.
// in your archive-your_custom_posttype.php or archive.php
<?php if ( have_posts() ) :
<?php while ( have_posts() ) : the_post(); ?>
<?php endwhile; ?>
<?php endif; ?>
Do you are showing the fields with the acf’s functions on your templates?
for example:
<?php the_field('my_field'); ?>
Here more info https://www.advancedcustomfields.com/resources/
For every custom fields you create, you’ll to need show it in your template.
For example: https://www.advancedcustomfields.com/resources/text/
Hi Beth.
Well, if you validate it with a simple if, something like this:
<?php if ( get_field('fireplace' ) ) : ?>
// do something
<?php the_field('fireplace'); ?>
<?php endif; ?>
This will show the field only if the field “fireplace” have something, this works with text fields and any field as well.
Here the docs about it https://www.advancedcustomfields.com/resources/true-false/
Like a extra point. To print the value of a custom field, you can use directly the function the_field('your_field_name')
but if do you want to check or save the value of the field in a variable, you can use get_field('your_field_name')
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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.