• Resolved Mark Shirley

    (@ravalde)


    Im trying to add custom post types to a page. They are made up of custom templates and custom fields and display fine. I have tried the code below from codex but I dont get anything appearing in the page

    <?php
    $args = array(
       'numberposts' => 2,
       'orderby' => 'rand',
       'post_type' => 'movies',
       'genre' => 'actors',
       'post_status' => 'red'
    );
    $show_albums = get_posts ( $args );
    
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • How does your loop looks like?

    Thread Starter Mark Shirley

    (@ravalde)

    The code above is all i did on to a page I also tried some code from the wp-codex below – not sure if it’s possible to add a CPT to a page as every tutorial I’ve tried just brings up any stuff that had been inputted in the post editor. All the custom template stuff ie custom field stuff never shows.

    <?php
    /**
     * Template Name: Page of Books
     *
     * Selectable from a dropdown menu on the edit page screen.
     */
    ?>
    
    <?php get_header(); ?>
    		<div id="container">
    			<div id="content">
    <?php
    $type = 'book';
    $args=array(
     'post_type' => $type,
     'post_status' => 'publish',
     'paged' => $paged,
     'posts_per_page' => 2,
     'ignore_sticky_posts'=> 1
    );
    $temp = $wp_query; // assign ordinal query to temp variable for later use
    $wp_query = null;
    $wp_query = new WP_Query($args);
    ?>
    <?php get_template_part( 'loop', 'index' );?>
    	</div><!-- #content -->
    </div><!-- #container -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Try changing this

    $temp = $wp_query; // assign ordinal query to temp variable for later use
    $wp_query = null;
    $wp_query = new WP_Query($args);

    to this

    query_posts( $args );

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘adding custom post types to a page’ is closed to new replies.