Count post views in loop

Few remarks: You should consider using a prefix on your meta key, for example lars_views, to minimize the risk of other plugins messing around with it. If you want to hide it from the edit screen, you can use an underscore: _lars_views. Consider wrapping the part of your code, that updates the counter, with if( … Read more

How can I display other user avatars on an author profile page?

Have you tried to specify the $userID parameter of get_the_author_meta(), like shown below: echo get_avatar(get_the_author_meta( ‘ID’, $post->post_author ), 150); This uses the post_author key from your secondary query, which has the ID as value, that said you should be able to shorten your code to: echo get_avatar( $post->post_author, 150);

How to append a query string to pagination?

Refer this: Paginate Codex I can see that you are using custom query so you put this below and outside the while loop <?php global $wp_query; $big = 999999999; // need an unlikely integer $args = array( ‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ), ‘format’ => ‘?page=%#%’, ‘total’ => $wp_query->max_num_pages, ‘current’ … Read more

Change post order by meta key, per post basis

Don’t try to make WP_Query, or SQL, do this. In the backend, don’t save artist_last_name save something like artist_sort_name instead, and set it to either first or last name accordingly, then sort on that normalized key. To sort conditionally with WP_Query— that is, to ignore my advise above and try to make WP_Query/SQL do this– … Read more

Foreach displays from last to first

Why wouldn’t you just pull them in the order you need instead of reversing the array? $args = array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, // correct key is posts_per_page, not numberposts ‘orderby’ => ‘date’ ‘order’ => ‘ASC’, ‘post_parent’ => $post->ID ); $attachments = get_posts( $args );

Why isn’t my multiple loops working?

This seems to work: while( have_posts() ): the_post(); the_content(); endwhile; $my_query = new WP_Query(‘page_id=40’); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;?> <div class=”entry”> <?php the_content(‘read more &raquo;’); ?> </div> <?php endwhile;

Escape current post from loop

The title of question is inaccurate. I think you don’t want to escape first post, instead you want to exclude current post. You can use the post__not_in argument in WP_Query. $args = array( ‘s’ => ‘searchTerm’ ); //Check if we are in a post of any type if( is_singular() ) { $post = get_queried_object(); $args[‘post__not_in’] … Read more