How to paginate this custom loop? [duplicate]

Likely this is happening because you are using a custom page template. Try the following. I’ve commented the steps along the way. Hope it helps. <?php //get the current page $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; //pagination fixes prior to loop $temp = $query; $query = null; //custom loop using WP_Query $query = new … Read more

Custom Shortcode, functions PHP WP_Query loop

You are returning inside your loop – so it returns on the first iteration, giving you one result only. You should build a string inside your loop instead, and only return when the loop is over. Something like $featured_properties=””; if( $featured_query->have_posts() ): while( $featured_query->have_posts() ) : $featured_query->the_post(); $featured_properties .= get_the_title() . ‘<br />’; endwhile; endif; … Read more

Link won’t show using the_permalink();

because the_title() expects a string for the $before and $after args, you need to use the string version of the permalink, in a string concatenation; <?php the_title(‘<h2 class=”wow”><a href=”‘.get_permalink().'”>’, ‘</a></h2>’); ?> you also had a missing >. https://developer.wordpress.org/reference/functions/get_permalink/

How to show just private posts in loop

You need to filter the main WordPress query using the pre_get_posts action. This code will get you started: function show_only_private_post_for_logged_in_users( $query ) { if ( ! $query->is_main_query() || is_admin() ) { return; } if ( is_user_logged_in() ) { $query->set( ‘post_status’, ‘private’ ); } } add_action( ‘pre_get_posts’, ‘show_only_private_post_for_logged_in_users’ ); It will only affect the main query … Read more

How to change posts order on Category and Tag archives?

You can use pre_get_posts action to modify this order. Here’s the code: function my_change_posts_order( $query ){ if ( ! is_admin() && ( is_category() || is_tag() ) && $query->is_main_query() ) { $query->set( ‘order’, ‘ASC’ ); } }; add_action( ‘pre_get_posts’, ‘my_change_posts_order’); What we do here is: We’re adding our function that will modify params for WP_Queries We … Read more

Adding Pagination on a Custom Author Page

Put the following code in your functions.php file. function limit_posts_per_page() { if ( is_author() ) // you can limit other pages as well ( i.e. is_archive() ), if need be. return 5; } add_filter( ‘pre_option_posts_per_page’, ‘limit_posts_per_page’ ); Make sure your using the author.php template, otherwise it wont work. Please have a look at twentyten’s author.php … Read more