• Hi there, im trying to display the very last post from my new custom post type called call to action. I have created this function which works great.

    add_action( 'init', 'register_themepost4', 20 );
    
    function register_themepost4() {
    
     $labels = array(
    
     'name' => _x( 'Call To Action', 'catchthemes_custom_post','catchthemes' ),
    
     'singular_name' => _x( 'calltoaction', 'catchthemes_custom_post', 'catchthemes' ),
    
     'add_new' => _x( 'Add New', 'catchthemes_custom_post', 'catchthemes' ),
    
     'add_new_item' => _x( 'Add New calltoaction', 'catchthemes_custom_post', 'catchthemes' ),
    
     'edit_item' => _x( 'Edit calltoaction', 'catchthemes_custom_post', 'catchthemes' ),
    
     'new_item' => _x( 'New calltoaction', 'catchthemes_custom_post', 'catchthemes' ),
    
     'view_item' => _x( 'View calltoaction', 'catchthemes_custom_post', 'catchthemes' ),
    
     'search_items' => _x( 'Search calltoaction', 'catchthemes_custom_post', 'catchthemes' ),
    
     'not_found' => _x( 'No calltoaction found', 'catchthemes_custom_post', 'catchthemes' ),
    
     'not_found_in_trash' => _x( 'No calltoaction found in Trash', 'catchthemes_custom_post', 'catchthemes' ),
    
     'parent_item_colon' => _x( 'Parent calltoaction:', 'catchthemes_custom_post', 'catchthemes' ),
    
     'menu_name' => _x( 'Call To Action', 'catchthemes_custom_post', 'catchthemes' ),
    
     ); 
    
     $args = array(
    
     'labels' => $labels,
    
     'hierarchical' => false,
    
     'description' => 'Call To Action',
    
     'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions'),
    
     'show_ui' => true,
    
     'show_in_menu' => true,
    
     'menu_position' => 5,
    
     'show_in_nav_menus' => true,
    
     'publicly_queryable' => true,
    
     'exclude_from_search' => true,
    
     'query_var' => true,
    
     'can_export' => true,
    
     'public' => true,
    
     'has_archive' => 'calltoaction',
    
     'capability_type' => 'post'
    
     );
    
     register_post_type( 'calltoaction', $args );//max 20 charachter cannot contain capital letters and spaces
    
    }

    But i now have difficulties displaying the actual posts from this new custom post type.

    I created this loop here:

    <?php
    	 // The Query
    	 wp_reset_query();
    	query_posts('post_type' => 'calltoaction'); if (have_posts()) : ?>  
    
        <?php while (have_posts()) : the_post();?>  
    
    		<?php the_permalink(); ?>
    
                <h3><?php echo substr(get_the_title(),0,58); ?></h3>
    
                <?php echo  get_excerpt(190); ?>
    
        <?php endwhile; ?>  
    
    <?php else : ?>  
    
    	Sorry, no call to action posts were found.
    <?php endif; ?> 
    
    <?php wp_reset_query(); ?>

    Clearly it must be the ‘post_type’ => ‘calltoaction’ line, but im not sure what else i could try as im not too hot with the syntax.

    Any help would be really appreciated.

    Thank you

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Display posts from custom post type’ is closed to new replies.