Multiple post type queries (with specific arguments for each)

Could you do something like this? <?php $args = array( ‘post_type’ => array(‘post’,’movie’,’actor’), ‘posts_per_page’ => ’20’, ); query_posts( $args ); while ( have_posts() ) : the_post(); global $post; if (($post_type == ‘movie’) && (get_post_meta($post->ID, ‘meta_key’, true) == ‘your-value’)) { // Display your content for Movie Post Type with meta value set } else if (($post_type … Read more

How do I prefix blog post urls as mysite.com/blog/%postname%/ but allow authors to still be located at mysite.com/authors/%nicename%?

You can set the author base independently by manipulating the $wp_rewrite global: function wpa55976_author_base() { global $wp_rewrite; $wp_rewrite->author_base=”authors”; $wp_rewrite->author_structure=”https://wordpress.stackexchange.com/” . $wp_rewrite->author_base . ‘/%author%’; // EDIT – rewrite rule to force author urls to resolve: add_rewrite_rule(‘authors/([^/]+)/?$’, ‘index.php?author_name=$matches[1]’, ‘top’); } add_action( ‘init’, ‘wpa55976_author_base’ ); Make sure to visit your permalinks page to flush rewrites after you add … Read more

Loop that displays the first post of every available custom post type?

This should work for you: // grab all public post types $post_types = get_post_types( array(‘public’ => true), ‘names’ ); // loops through each post type foreach( $post_types as $type ) { // setup the query $query_args = array( ‘post_type’ => $type, ‘posts_per_page’ => 1 ); // perform the query $items = get_posts( $query_args ); // … Read more

Custom post type code hides navigation

It looks like you’re overwriting the nav menu query. By adding the ! is_admin() and $query->is_main_query() conditionals, you can ensure that you’re targeting the main query for posts on the front end. add_filter( ‘pre_get_posts’, ‘my_get_posts’ ); function my_get_posts( $query ) { if ( ! is_admin() && $query->is_main_query() && is_home() ) $query->set( ‘post_type’, array( ‘post’, ‘page’, … Read more

Exclude custom post type from list

<?php $custom_post_types = get_post_types( array( ‘_builtin’ => false, ‘public’ => true ), ‘objects’ ); ksort( $custom_post_types, SORT_ASC ); echo ‘<ul>’; foreach ( $custom_post_types as $custom_post_type ) { $exclude = array( ‘products’, ‘sales’ ); if( TRUE === in_array( $custom_post_type->name, $exclude ) ) continue; $custom_post_type->permalink = get_post_type_archive_link( $custom_post_type->name ); echo ‘<li>’; echo ‘<a href=”‘ . $custom_post_type->permalink . … Read more

Combining custom post type and post category

Must have both The following arguments array searches for the post-type-slug videos and category-slug video. It doesn’t use pagination by setting posts_per_page to -1 and only returns published posts. $args = array( ‘post_type’ => ‘videos’, ‘category_name’ => ‘video’, ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’ ); Either this or that If you are trying to show … Read more