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’ )) : ?>

Get Value of Post before

<?php $previous_post=null; if ( have_posts() ) { while ( have_posts() ) { the_post(); global $post; if($previous_post!=null) { /// Do what ever you want to do with previous post $previous_post. } $description = get_post_meta( get_the_ID( ), ‘metabox_description’, true ); echo $description; // Add: echo $description_from_post_before; $previous_post = $post; } // end while } // end if … Read more

Using Wp_Query without the loop?

The query itself doesn’t change globals, however you are correct that the_post() does. The most contained way to just retrieve posts (as array of results) is using get_posts() function, which is wrapper around WP_Query and takes same arguments.

Including all post id’s of a custom post type into an array

Save yourself a loop with get_posts and ‘fields’ => ‘ids’. // Default Query function do_query($args = null) { $default_args = array( ‘numberposts’ => -1, ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’, ‘fields’ => ‘ids’, ); if (null !== $args && !empty($args)) $args = array_merge($default_args, $args); else $args = $default_args; return get_posts($args); } // Customize Query $post_ids … Read more

WP_Query fails despite having 1 post

T a look at how to properly construct a query with WP_Query. $args = array( ‘post_type’ => ‘cameras’, ‘posts_per_page’ => 5, ); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo ‘<ul>’; while ( $the_query->have_posts() ) { $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; } echo ‘</ul>’; } else … Read more