How to print different informations for different post types inside The Loop?

Of course, you can use conditions like this inside the loop. if ( ‘event’ == get_post_type( get_the_ID() ) ) { // do something } Full code would be // The Loop if ( $query->have_posts() ) : ?> <?php if ( is_home() && ! is_front_page() ) : ?> <header> <h1 class=”page-title screen-reader-text”><?php single_post_title(); ?></h1> </header> <?php … Read more

Order Categories by Character Count

This is probably more a question about PHP rather than WordPress, and as such may be closed as off-topic for this site. That said, you can usort() to sort an array using a custom comparison function: usort( $listings->loop[‘cats’], function( $a, $b ){ return strlen( $a->name ) – strlen( $b->name ); } ); After the call … Read more

Custom Wp_query loop takes very long

I found a solution to my question. I used the following code: global $wpdb; if($t_query->have_posts()){ while($t_query->have_posts()){ $t_query->the_post(); echo $wpdb->last_query.”\r\n”; } } and it showed there was an action somewhere hooked to the_post hook, sending requests to update some meta every time a post was processed. So, the answer to my question is: I should have … Read more

Prevent duplicating specific column from database table

This is more of a general PHP question than a WordPress one. Use an array with the county as a key to group up your results. $groups = array(); foreach( $results as $result ) { $groups[$result->county][] = $result; } var_dump or print_r on $groups to see how this groups up your results. You can then … Read more

What template file is used by default for posts?

You can create new template php file. //Template Name : Single Page Template get_header(); if ( have_posts() ) : while ( have_posts() ) : the_post(); the_content(); the_permalink();//this is for the <a> bunch you are looking for endwhile; endif; get_footer(); Here , you can use “//” or “/** **/” to set the Template name , it … Read more