How to loop only categories without posts (+ show category featured image with acf) [closed]

Well, in WP the word “loop” is mainly related to posts. It’s easier to say that you want to display categories. All you have to do is to get them using get_categories function and display them. <?php $categories = get_categories( array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’ ) ); if ( ! empty( $categories ) … Read more

Create A Loop With A Variable Number of Posts For Each Bootstrap Row?

The easy-but-a-bit-hacky way to get there would be to initialize a counter variable before your loop and then use that to tell what post you’re on. something like so: $paged = (get_query_var(‘paged’)) ? absint(get_query_var(‘paged’)) : 1; $args = array( ‘post_type’ => ‘workshop’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 11, ‘paged’ => $paged, ); $customQuery = new … Read more

Get first URL from post content

I think this question might put you in the right direction. In case that link is broken, here’s the answer as provided by Jon Fabry in that thread. $post_link = get_the_permalink(); if ( preg_match(‘/<a (.+?)>/’, get_the_content(), $match) ) { $link = array(); foreach ( wp_kses_hair($match[1], array(‘http’)) as $attr) { $link[$attr[‘name’]] = $attr[‘value’]; } $post_link = … Read more

How can marge these loop code?

Here’s an example how you could use your first code in the second one. In my code I also took the liberty to suggest one way of making your code more clear and easier to read by splitting the code into separate functions. // add the following helper functions to functions.php function travel_trip_type_image_url( int $term_id … Read more

How to use offset in WP_Query

offset is one of the arguments that you can pass to WP_Query, so it belongs in the $args array: $args = array( ‘post_type’ => ‘post’, ‘category_name’ => ‘category’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘showposts’ => 4, ‘offset’ => 4, ); PS: $wp_query is a reserved variable used by the main query. When creating your … Read more