Wrap group of wp query posts to parent div by date/year

This cannot be done only by querying database. Firstly, you have to iterate through all items and create array of posts grouped by dates. $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘event’, ‘meta_key’ => ‘event_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’ ); $wpquery = new WP_Query($args); $posts = $wpquery->get_posts(); $ordered_posts = array(); foreach ($posts … Read more

Counting number of images from loop

You can get images with foreach loop but first you have to print_r($images) and then get the value of the array something like this $images[‘image’] or $images[‘src’] or $images[‘url’] etc. But first check is there any record where you are getting get_sub_field(‘image’) all images. <?php if ( $images = get_sub_field(‘image’) ) : print_r($images); foreach($images as … Read more

ACF – Compare user and post data

There is a PHP function: preg_grep which accepts $pattern and $input as a parameters and returns you an array of matches. If you want to get first match just assign it to variable, e.x.: $field_os = array(‘windows-7′,’mac-os-10.07′,’linux-ubunto-16.04’); $user_os_type = “windows”; $matches = preg_grep(“https://wordpress.stackexchange.com/” . $user_os_type . “https://wordpress.stackexchange.com/”, $field_os); var_dump($matches); /* Prints: array(1) { [0]=> string(9) … Read more