• Resolved Iva

    (@supersonicsquirrel)


    This is my custom post type – meant to show a small picture of an artist’s recent release, with a title and custom fields. How do I query it, if I want it as a custom loop in the sidebar? Can it be done with the get_posts function? Thanks in advance.

    add_action( 'init', 'register_imnet_recentrelease' ); 
    
    function register_imnet_recentrelease() {  
    
        $labels = array(
            'name' => _x( 'recent release', 'recent release' ),
            'singular_name' => _x( 'recent release', 'recent release' ),
            'add_new' => _x( 'Add New', 'recent release' ),
            'add_new_item' => _x( 'Add New recent release', 'recent release' ),
            'edit_item' => _x( 'Edit recent release', 'recent release' ),
            'new_item' => _x( 'New recent release', 'recent release' ),
            'view_item' => _x( 'View recent release', 'recent release' ),
            'search_items' => _x( 'Search recent releases', 'recent release' ),
            'not_found' => _x( 'No recent releases found', 'recent release' ),
            'not_found_in_trash' => _x( 'No recent releases found in Trash', 'recent release' ),
            'parent_item_colon' => _x( 'Parent recent release:', 'recent release' ),
            'menu_name' => _x( 'recent releases', 'recent release' ),
        );  
    
        $args = array(
            'labels' => $labels,
            'hierarchical' => false,
            'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'menu_position' => 8,
            'menu_icon' => 'https://yourdomain.com/images/menuicon.png',
            'show_in_nav_menus' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => true,
            'has_archive' => true,
            'query_var' => true,
            'can_export' => true,
            'rewrite' => true,
            'capability_type' => 'page'
        );  
    
        register_post_type( 'recentrelease', $args );
    }
Viewing 1 replies (of 1 total)
  • Thread Starter Iva

    (@supersonicsquirrel)

    I tried this, but it does not work:

    <h4 class="widgettitle">Recent Releases</h4>
    
    <?php $postslist = get_posts('numberposts=5&order=DESC&post_type=recentrelease'); foreach ($postslist as $post) : setup_postdata($post); ?>
    <div class="recent-post">
    <p><?php if ( has_post_thumbnail() ) the_post_thumbnail( array( 128, 128 ), array( 'class' => 'alignleft') ); else { ?><?php } ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?>&raquo;<br />
    <span class="date"><?php the_time(get_option('date_format')); ?></span>
    </a></p></div>
    <div class="clear">&nbsp;</div>
    <?php endforeach; ?>
    </div>
    <div class="clear">&nbsp;</div>
Viewing 1 replies (of 1 total)
  • The topic ‘The best way to query this post type?’ is closed to new replies.