How to get all images and their thumbnails from wp media library

Here’s what you can do. Get a list of all available thumbnail sizes Query all the attachments For each attachment size, get it’s URL and save it into the array Let’s change your code into this: function get_images_highcompress_data() { $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image/jpeg,image/jpg,image/png’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => -1, ‘orderby’ … Read more

WP_Query to loop a Custom Field, Custom Post Types do not show

There’s a missing opening quote and closing bracket on this line: <i class=<?php the_field(‘course_feature_icon’); ?>”</i> Needs to be: <i class=”<?php the_field(‘course_feature_icon’); ?>”></i> That’s all that’s wrong with your code. It should then work assuming: You have a custom field, course_feature_icon, whose value is a valid CSS class. You have the necessary CSS to add an … Read more

Group posts by custom field

You’re close. You have: foreach (get_child_pages(wp_get_post_parent_id(get_the_ID())) as $s) { echo ‘<li><a href=”‘ . get_the_permalink($s->ID) . ‘”>’ . get_the_title($s->ID) . ‘</a></li>’; } We need to add a layer above that to show the two lists. However we can’t assume that the posts of one type will all come out together (i.e. all of one category, then … Read more

Counting number of posts with Category B in Category A

Make use of the WP_Query class, namely the tax_query and fields parameters. Get the count from the $found_posts property. Please note, this is exemplary code. $query = new WP_Query( [ ‘post_type’ => ‘games’, ‘tax_query’ = [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘game_status’, ‘field’ => ‘slug’, ‘terms’ => [ ‘beaten’ ], ], [ ‘taxonomy’ => … Read more

Duplicate Queries

Generally speaking, you could use the WP Transients API to save the query. // Get any existing copy of our transient data if ( false === ( $special_query_results = get_transient( ‘special_query_results’ ) ) ) { // It wasn’t there, so regenerate the data and save the transient $special_query_results = new WP_Query( ‘cat=5&order=random&tag=tech&post_meta_key=thumbnail’ ); set_transient( ‘special_query_results’, … Read more