Is it necessary to reset the query after using get_posts()?
No. get_posts() does not modify global $wp_query variable and it doesn’t need to be cleaned up. Note that if you further use setup_postdata() you do need to wp_reset_postdata() afterwards.
No. get_posts() does not modify global $wp_query variable and it doesn’t need to be cleaned up. Note that if you further use setup_postdata() you do need to wp_reset_postdata() afterwards.
This the post__not_in arg should work dandy for you: $args = array( ‘numberposts’ => 5, ‘offset’ => 0, ‘category’ => 7, ‘post__not_in’ => array( $post->ID ) ); $myposts2 = get_posts($args);
You can’t actually pass a taxonomy-related argument to get_posts(). (Edit: actually, yes you can. The Codex is just somewhat unclear. Looking at source, get_posts() is, at its heart, just a wrapper for WP_Query().) You can pass meta keys/values, and post types, but not taxonomies such as post format. So for this line: $myposts = get_posts(‘numberposts=-1&orderby=post_date&order=DESC’); … Read more
If you look at the get_posts documentation on Codex, you can see there’s a parameter for number of posts you want to display: $numberposts (integer) (optional) Number of posts to return. Set to 0 to use the max number of posts per page. Set to -1 to remove the limit. Default: 5 That’s why it’s … Read more
First, you should always use the WordPress AJAX methods, not a custom function for that. See AJAX in Plugins in the Codex. With that practice in mind, you can set up your request like this. Change the AJAX URL to <?php echo admin_url(‘admin-ajax.php’); ?> and add the ‘action’: key with the value of the specific … Read more
I have bit of trouble understanding your question. Taxonomy (like category) slug or term (like uncategorized) slug? get_term_children() works with terms so I will stick with that. Try this: $term = get_term( $id, $taxonomy ); $slug = $term->slug;
I would strongly advise against using $post->guid – WordPress now generates them in the form; http:/example.com/?attachment_id=ID Use the same method that many of the attachment-related functions use; $filename = basename ( get_attached_file( $data->ID ) );
I’m a bit confused. If you want to get onlya element from the posts array you can get it like this: reset($current_user_posts) – first post end($current_user_posts) – lat post But if you want to get just one post with the get_posts() you can use the posts_per_page argument to limit the results. $args = array( ‘author’ … Read more
Yes, it is possible. Sample code, has to be tested and refined: // get all posts $posts = get_posts( array ( ‘numberposts’ => -1 ) ); foreach ( $posts as $post ) { // check the slug and run an update if necessary $new_slug = sanitize_title( $post->post_title ); if ( $post->post_name != $new_slug ) { … Read more
I could be wrong, but from what I’m seeing, “setup_postdata()” should be used when doing a custom select query (not just query_posts): http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query As well, if you want to use tags like “the_title()” and “the_permalink()” with that custom select query … you’ll need to use the variable name $post specifically (not another variable name) in … Read more