Unable to change the “Read more” text inside the_excerpt

Try making the post object accessible using global and use get_permalink($post->ID) function new_excerpt_more( $more ) { global $post; return ‘<a class=”read-more” href=”‘. get_permalink($post->ID) . ‘”>Custom text</a>’; } add_filter( ‘excerpt_more’, ‘new_excerpt_more’ ); Ensure the code is in your functions.php file.

Get 1 more post in loop

You should probably add a meta query to your WP_Query() args: $loop = new wp_query( array( ‘posts_per_page’ => 3, // Meta Query ‘meta_query’ => array( array( ‘key’ => ‘skip_me’, ‘value’ => ‘true’, ‘compare’ => ‘!=’ ) ) ) ); Or you could perhaps go with the simpler version in this case: $loop = new wp_query( … Read more

Single.php different behaviour from admin to non-admin

Per a comment, the problem was due to the use of query_posts which clobbers the main query. Please don’t use query_posts. It should be noted that using this to replace the main query on a page can increase page loading times, in worst case scenarios more than doubling the amount of work needed or more. … Read more

Get author_id in wordpress

Check the value in the get_query_var() function. An example, that works:– $author = get_user_by( ‘slug’, get_query_var( ‘author_name’ ) ); echo $author->ID; If you like only the author of post, inside the loop, then use the template tag get_the_author().

How to add a specific div element to the first post in a row?

Well… Of course it doesn’t work – $count is undefined and you never change it’s value. You probably want to have there something like this: <?php if ($loop) : while ($loop->have_posts()) : $loop->the_post(); ?> <li class=”grid_4 portfolio-post”> <?php if ($loop->current_post == 0) echo ‘<div class=”newest”>NEW</div>’; ?> <a href=”https://wordpress.stackexchange.com/questions/138934/<?php the_permalink(); ?>” title=”<?php the_title(); ?>”> <header class=”post-thumb”> … Read more

is_active-sidebar loop

is_active_sidebar has a single value, whether it is the sideabar id or name. If you have more than one sidebar, you should repeat is_active_sidebar, each one with a specific sidebar id or name. You would do something like this <?php if ( is_active_sidebar( ‘available-course-list-1’ ) && is_active_sidebar( ‘available-course-list-2’ )) : ?>

Getting a custom field in the middle of a loop

You should not be using query_posts at all, it is just problematic and is prone to failure Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of … Read more

Update status of all posts in a category

I am sure there’s an easier way to accomplish this, but this how I would’ve done. Query all posts with category X and status X Update query results with status Y. $target_category = ‘news’; $change_status_from = ‘draft’; $change_status_to = ‘publish’; $update_query = new WP_Query(array(‘post_status’=>$change_status_from, ‘category_name’=>$target_category, ‘posts_per_page’=>-1)); if($update_query->have_posts()){ while($update_query->have_posts()){ $update_query->the_post(); wp_update_post(array(‘ID’=>$post->ID, ‘post_status’=>$change_status_to)); } } You can … Read more

Loop for sticky posts

The issue is that you are using the function query_posts this only queries the default result on that page. It’s advised that you use wp_query instead, it just eliminates the margin for error or unexpected results. You can create a new query like below, and specify explicitly how many posts to return: <?php $sticky = … Read more