Only get_posts of certain post formats

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

How to get post content by calling ajax?

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

get_posts – get all posts by author 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

setup_postdata() does not seem to be working?

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

Query for custom post type? [closed]

query_posts( array( ‘post_type’ => array(‘post’, ‘portfolio’) ) ); which shows both normal posts and posts inside portfolio type or query_posts(‘post_type=portfolio’); for only portfolio. Use as normal WP Query – read the Codex: http://codex.wordpress.org/Function_Reference/query_posts#Usage and http://codex.wordpress.org/Function_Reference/query_posts#Post_.26_Page_Parameters <?php query_posts(array( ‘post_type’ => ‘portfolio’, ‘showposts’ => 10 ) ); ?> <?php while (have_posts()) : the_post(); ?> <h2><a href=”https://wordpress.stackexchange.com/questions/6417/<?php the_permalink() … Read more