Hey @ana_p
I see a few problems with your code.
First of all, you’re using the meta_key
and meta_value
incorrectly.
meta_key
is the name of the field, in your case ‘training_date’
meta_value
is the value to compare the field to
Check the WP Meta Query documentation for more details, https://codex.wordpress.org/Class_Reference/WP_Meta_Query
Finally, I think your approach to compare only the month to the training dates is incorrect because this way you will get trainings of past and future years too.
So my suggestion is to use start and end dates for the given month and use meta_query
with 'BETWEEN'
To learn more about meta_query, please take a look at this page: https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
Create start and end dates for the given month like this
$month = '02';
$start_date = date( 'Y' . $month . '01' );
$end_date = date( 'Y' . $month . 't' );
Use those dates to find training dates ‘BETWEEN’ them in a meta_query
$args = array(
'post_type' => 'job_listing',
'posts_per_page' => '30',
'meta_query' => array(
array(
'key' => 'training_date',
'value' => array( $start_date, $end_date ),
'compare' => 'BETWEEN',
'type' => 'DATE'
)
)
);
I hope this helps.
Cool, I see the problem with your code; you’re not passing the correct arguments to wp_get_attachment_image. It expects as a first argument an attachment ID. In your case, you’re passing the whole image array.
So instead of $images[$rand]
you should get the ID
out of this array.
wp_get_attachment_image( $images[$rand]['ID'], $size );
Panos
Hey @codeview
Have a look at the Gallery field documentation here https://www.advancedcustomfields.com/resources/gallery/
Under section “Basic list of images” you will find how to use the wp_get_attachment_image()
function
Panos
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.