WP_Query calls all posts?
There’s no such parameter as category for WP_Query, so WP is ignoring it. You should use category_name, where the value is the slug of the category.
There’s no such parameter as category for WP_Query, so WP is ignoring it. You should use category_name, where the value is the slug of the category.
The simplest thing would be to add a class to the link that contains the post ID. <a href=”https://wordpress.stackexchange.com/questions/97059/<?php the_permalink() ?>” class=”post-<?php echo get_the_ID(); ?>”> You can then write a custom CSS function, put it in functions.php and hook to the wp_head. This function only serves to echo the necessary CSS to highlight the link. … Read more
Yes, there are a few improvements. Needlessly opening and closing PHP tags is a timewaster, makes it harder to read, and means more typing PHP Alt/short style syntax isn’t going to play as nicely with the editor. Use {} instead, and your IDE may even help you type out the closing brace automagically. Query_posts, never, … Read more
After a lot of trial and error I learnt that WP_User_Query takes an argument fields which can be set to ‘all_with_meta’. This reduces number of queries to two for any number of users that are fetched in a single go and also provides benefits of caching. Usage would look like: $user_query = new WP_User_Query( array(‘include’ … Read more
You can try this: $args = array( ‘post__not_in’ => get_option( ‘sticky_posts’ ), ‘posts_per_page’ => 5, ); $recent = new WP_Query( $args ); to exclude the sticky posts. You can read more about it here in the Codex.
The code you posted will only make difference in adding <div class=”first-post”></div> for the first post, so it still displays same information for all posts. Try this instead: <?php $queryObject = new Wp_Query( array( ‘showposts’ => 5, ‘post_type’ => array(‘post’), ‘category_name’ => videos, ‘orderby’ => 1, )); // The Loop if ( $queryObject->have_posts() ) : … Read more
If wp_create_user executes successfully, it will return the id of the created user. [Codex] Here it is in action with an error handler. $user_id = wp_create_user(); if( is_wp_error($user_id) ) { echo $user_id->get_error_message(); } else { //add into custom table echo $user_id; }
Isn’t it so that you have exactly 10 posts and you’re showing them all on first page. $found_posts – The total number of posts found matching the current query parameters found_posts on your first page shows 10. All of these posts are shown on first page. So there are no posts to show on second … Read more
get_posts() has some defaults set, including numberposts equal to 5. Since it’s not considered to be a loop by itself those are independent and not affected by admin settings. So simply pass in arguments numberposts/posts_per_page (same thing) number for how many posts you want or -1 for all matching posts.
This answer explains the differences. They all use WP_Query, all parameters being equal there is no difference in speed, it’s just a question of which is easier for you for your particular needs (hint: it will never be query_posts, which should basically never be used). You should query the database as few times as possible, … Read more