Getting a list of custom posts by author

Something like this should work: // Assuming you’ve got $author_id set // and your post type is called ‘your_post_type’ $args = array( ‘author’ => $author_id, ‘post_type’ => ‘your_post_type’, ); $author_posts = new WP_Query( $args ); if( $author_posts->have_posts() ) { while( $author_posts->have_posts() ) { $author_posts->the_post(); // title, content, etc $author_posts->the_title(); $author_posts->the_content(); // you should have access … Read more

How to check if a WP_Query has data

Change it up a bit and use have_posts method to check if there are any results: <?php $args = array( ‘post_type’ => ‘questions’, ‘posts_per_page’ => ‘3’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘types’, ‘field’ => ‘slug’, ‘terms’ => ‘customer-service’ ) ) ); $loop = new WP_Query( $args ); if ($loop->have_posts()){ ?> <h4>Frequently Asked Questions</h4> <ul … Read more

How to limit the number of terms (terms acts like categories)

number (integer) The maximum number of terms to return. Default is to return them all. http://codex.wordpress.org/Function_Reference/get_terms So… $terms = get_terms(‘new_category’,array(‘number’ => 5)); But there is a good chance that some of your terms will never show up. You will get the first five or the last five (in the example) depending on the sort order. … Read more

DOING_AUTOSAVE function in wordpress

That conditional logic first checkes if the constant DOING_AUTOSAVE is defined by using the PHP function defined(‘SOME_CONSTANT_NAME’). Then the logic checks to see if the state/value of the constant DOING_AUTOSAVE is true, that’s the second part of the conditional right after the && (and). So if DOING_AUTOSAVE has been defined in the request lifecycle and … Read more

Allow user to Edit Posts but not Add New?

You will have to do something like this: function hide_buttons() { global $current_screen; if($current_screen->id == ‘edit-post’ && !current_user_can(‘publish_posts’)) { echo ‘<style>.add-new-h2{display: none;}</style>’; } } add_action(‘admin_head’,’hide_buttons’); See: http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link for reference

Featured Image Panel Missing From Custom Post Type in WordPress 3.2

Change this: // This theme uses post thumbnails add_theme_support( ‘post-thumbnails’, array(‘post’, ‘page’) ); To this: // This theme uses post thumbnails add_theme_support( ‘post-thumbnails’ ); The problem is that the array is explicit, when used. So, post-thumbnail support will only be added to post-types included in the array. Omit the array, in order to add Theme … Read more