Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been reading a lot about my simple issue, but wasn't able to find the simple answer, so, please excuse my noobieness. I have a custom post type registered in functions.php, like so:

<?php
function my_custom_post_procedimentos() {
$labels = array(
    'name'               => _x( 'Procedimentos', 'post type general name' ),
    'singular_name'      => _x( 'Procedimento', 'post type singular name' ),
    'add_new'            => _x( 'Add New', 'Procedimento' ),
    'add_new_item'       => __( 'Add New Procedimento' ),
    'edit_item'          => __( 'Edit Procedimentos' ),
    'new_item'           => __( 'New Procedimento' ),
    'all_items'          => __( 'All Procedimentos' ),
    'view_item'          => __( 'View Procedimentos' ),
    'search_items'       => __( 'Search Procedimentos' ),
    'not_found'          => __( 'No Procedimento found' ),
    'not_found_in_trash' => __( 'No Procedimento found in the Trash' ), 
    'parent_item_colon'  => '',
    'menu_name'          => 'Procedimentos'
);
$args = array(
    'labels'        => $labels,
    'description'   => 'Holds our Procedimentos specific data',
    'public'        => true,
    'menu_position' => 5,
    'supports'      => array( 'title', 'editor', 'thumbnail' ),
    'has_archive'   => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'can_export' => true
);
register_post_type( 'procedimentos', $args );
}
add_action( 'init', 'my_custom_post_procedimentos' );
?>

and this is the single-procedimentos.php loop:

<?php get_header(); ?>
<div class="contcolsopen">
<div class="post">
     <?php if(have_posts()) : ?>
      <?php while(have_posts()) : the_post(); ?>
            <?php the_title(); ?>
            <?php the_content(); ?>
      <?php endwhile; ?>
      <?php endif; ?>
</div><!--post-end-->
</div><!--contcolsopen-end-->
<?php get_footer(); ?>

I'm using /%category%/%postname%/ as the permalinks structure, but no cigar.

So: When I have a custom post type to show a list of them on the front page, where each list-item (perma)links to its respective single page, what are the loop structure for the single-[cpt] and the page-[cpt]?

Please let me know if I'm not being clear enough.

Thank you in advance.

This part refers to @Warwick's kind request on a comment below:

object(WP_Query)#168 (47) { ["query_vars"]=> array(58) { ["page"]=> int(0)       ["procedimento"]=> string(36) "prostatectomia-radical-laparoscopica" ["post_type"]=> string(12) "procedimento" ["name"]=> string(36) "prostatectomia-radical-laparoscopica" ["error"]=> string(0) "" ["m"]=> int(0) ["p"]=> int(0) ["post_parent"]=> string(0) "" ["subpost"]=> string(0) "" ["subpost_id"]=> string(0) "" ["attachment"]=> string(0) "" ["attachment_id"]=> int(0) ["static"]=> string(0) "" ["pagename"]=> string(0) "" ["page_id"]=> int(0) ["second"]=> string(0) "" ["minute"]=> string(0) "" ["hour"]=> string(0) "" ["day"]=> int(0) ["monthnum"]=> int(0) ["year"]=> int(0) ["w"]=> int(0) ["category_name"]=> string(0) "" ["tag"]=> string(0) "" ["cat"]=> string(0) "" ["tag_id"]=> string(0) "" ["author_name"]=> string(0) "" ["feed"]=> string(0) "" ["tb"]=> string(0) "" ["paged"]=> int(0) ["comments_popup"]=> string(0) "" ["meta_key"]=> string(0) "" ["meta_value"]=> string(0) "" ["preview"]=> string(0) "" ["s"]=> string(0) "" ["sentence"]=> string(0) "" ["fields"]=> string(0) "" ["menu_order"]=> string(0) "" ["category__in"]=> array(0) { } ["category__not_in"]=> array(0) { } ["category__and"]=> array(0) { } ["post__in"]=> array(0) { } ["post__not_in"]=> array(0) { } ["tag__in"]=> array(0) { } ["tag__not_in"]=> array(0) { } ["tag__and"]=> array(0) { } ["tag_slug__in"]=> array(0) { } ["tag_slug__and"]=> array(0) { } ["ignore_sticky_posts"]=> bool(false) ["suppress_filters"]=> bool(false) ["cache_results"]=> bool(true) ["update_post_term_cache"]=> bool(true) ["update_post_meta_cache"]=> bool(true) ["posts_per_page"]=> int(10) ["nopaging"]=> bool(false) ["comments_per_page"]=> string(2) "50" ["no_found_rows"]=> bool(false) ["order"]=> string(4) "DESC" } ["tax_query"]=> NULL ["meta_query"]=> object(WP_Meta_Query)#224 (2) { ["queries"]=> array(0) { } ["relation"]=> NULL } ["post_count"]=> int(1) ["current_post"]=> int(-1) ["in_the_loop"]=> bool(false) ["comment_count"]=> int(0) ["current_comment"]=> int(-1) ["found_posts"]=> int(1) ["max_num_pages"]=> int(0) ["max_num_comment_pages"]=> int(0) ["is_single"]=> bool(true) ["is_preview"]=> bool(false) ["is_page"]=> bool(false) ["is_archive"]=> bool(false) ["is_date"]=> bool(false) ["is_year"]=> bool(false) ["is_month"]=> bool(false) ["is_day"]=> bool(false) ["is_time"]=> bool(false) ["is_author"]=> bool(false) ["is_category"]=> bool(false) ["is_tag"]=> bool(false) ["is_tax"]=> bool(false) ["is_search"]=> bool(false) ["is_feed"]=> bool(false) ["is_comment_feed"]=> bool(false) ["is_trackback"]=> bool(false) ["is_home"]=> bool(false) ["is_404"]=> bool(false) ["is_comments_popup"]=> bool(false) ["is_paged"]=> bool(false) ["is_admin"]=> bool(false) ["is_attachment"]=> bool(false) ["is_singular"]=> bool(true) ["is_robots"]=> bool(false) ["is_posts_page"]=> bool(false) ["is_post_type_archive"]=> bool(false) ["query_vars_hash"]=> string(32) "1d123a103cba5a796526d6ce635a1001" ["query_vars_changed"]=> bool(false) ["thumbnails_cached"]=> bool(false) ["query"]=> array(4) { ["page"]=> string(0) "" ["procedimento"]=> string(36) "prostatectomia-radical-laparoscopica" ["post_type"]=> string(12) "procedimento" ["name"]=> string(36) "prostatectomia-radical-laparoscopica" } ["request"]=> string(184) "SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_name = 'prostatectomia-radical-laparoscopica' AND wp_posts.post_type = 'procedimento' ORDER BY wp_posts.post_date DESC " ["posts"]=> &array(2) { [0]=> object(WP_Post)#234 (24) { ["ID"]=> int(20) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2013-03-12 13:55:55" ["post_date_gmt"]=> string(19) "2013-03-12 13:55:55" ["post_content"]=> string(2188) "Vivamus nec i'm in the shizzle egizzle nisi mah nizzle pretizzle. Vivamizzle sit amizzle lacus. Nam for sure nisl lacus auctor boom shackalack. Shizzlin dizzle suscipit things ipsizzle. Mammasay mammasa mamma oo sa in mammasay mammasa mamma oo sa. Vestibulum enim enizzle, ass sizzle, ma nizzle pizzle, cool ma nizzle, check out this. Nullam vitae pede break it down erizzle mah nizzle pharetra. Quisque pede phat, ma nizzle pulvinizzle, doggy a, mollis black shit, yo mamma. Donizzle at dui. You son of a bizzle risus purus, elementum consectetuer, sollicitudizzle gangster, consequizzle imperdizzle, dizzle. Black away things eu mi rutrum cool. Curabitur da bomb sagittizzle ipsum. Pimpin' funky fresh morbi yo mamma senectizzle fo shizzle netus ghetto malesuada yo mamma fo shizzle turpis i'm in the shizzle. My shizz est. Fo shizzle elementum. Ut erizzle felizzle, crackalackin rizzle, suscipizzle ac, shut the shizzle up check it out, nisl. For sure sagittizzle gravida velizzle. The bizzle posuere auctizzle maurizzle. Sizzle a rizzle ut crunk its fo rizzle tincidunt. Maecenas mah nizzle fo. Boom shackalack izzle daahng dawg shut the shizzle up maurizzle elementizzle ass. Nunc izzle check it out sit amizzle fo shizzle my nizzle ultricizzle fo shizzle. In velizzle tortizzle, dang izzle, bizzle quizzle, adipiscing quizzle, i'm in the shizzle. The bizzle crazy leo, aliquam consequizzle, shizzle my nizzle crocodizzle nizzle, dictum sed, turpizzle. Dope fo shizzle. Crizzle hizzle. Prizzle vitae sheezy fizzle libero pizzle adipiscing. Ghetto izzle phat eu nibh ullamcorper cool. Fizzle rizzle sapizzle nizzle erat. Suspendisse lorizzle shit, sollicitudin sed, mattizzle izzle, dope nec, justo. Doggy shizznit ligula. Own yo' feugiat, bling bling a funky fresh tempizzle, bling bling metizzle tincidunt ante, dang dapibizzle pede boofron shizzlin dizzle we gonna chung. Phasellus quizzle pimpin', imperdiet id, tempus crunk, sempizzle we gonna chung, sapizzle. Ut mollizzle sizzle vizzle shut the shizzle up. Sizzle ante nibh, you son of a bizzle go to hizzle, vestibulizzle daahng dawg, funky fresh eu, velit. Sizzle a away. Dope nizzle magna sizzle dang risus ghetto congue." ["post_title"]=> string(48) "Pieloplastia Laparoscópica e Obstrução de JUP" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(45) "pieloplastia-laparoscopica-e-obstrucao-de-jup" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2013-03-12 13:55:55" ["post_modified_gmt"]=> string(19) "2013-03-12 13:55:55" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(55) "http://localhost:8888/?post_type=procedimento&p=20" ["menu_order"]=> int(0) ["post_type"]=> string(12) "procedimento" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } [1]=> object(WP_Post)#235 (24) { ["ID"]=> int(19) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2013-03-12 13:51:38" ["post_date_gmt"]=> string(19) "2013-03-12 13:51:38" ["post_content"]=> string(601) "Lorizzle ipsum dolizzle ma nizzle amizzle, izzle adipiscing dope. Nullam sapizzle velizzle, shizznit volutpizzle, suscipizzle quizzle, fo shizzle mah nizzle fo rizzle, mah home g-dizzle vizzle, arcu. Pellentesque gizzle tortor. Dope erizzle. Yippiyo fo dolor dapibus turpis tempizzle dizzle. Mauris check it out nibh izzle gangster. Pizzle break yo neck, yall sheezy. Brizzle fo shizzle rhoncizzle nisi. In you son of a bizzle habitasse platea dictumst. Sure dapibizzle. Curabitizzle tellus urna, pretium eu, mattizzle ac, eleifend vitae, nunc. Dang suscipizzle. Integer semper things fizzle purizzle." ["post_title"]=> string(37) "Prostatectomia Radical Laparoscópica" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(36) "prostatectomia-radical-laparoscopica" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2013-03-13 13:12:58" ["post_modified_gmt"]=> string(19) "2013-03-13 13:12:58" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(55) "http://localhost:8888/?post_type=procedimento&p=19" ["menu_order"]=> int(0) ["post_type"]=> string(12) "procedimento" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } } ["post"]=> object(WP_Post)#226 (24) { ["ID"]=> int(19) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2013-03-12 13:51:38" ["post_date_gmt"]=> string(19) "2013-03-12 13:51:38" ["post_content"]=> string(601) "Lorizzle ipsum dolizzle ma nizzle amizzle, izzle adipiscing dope. Nullam sapizzle velizzle, shizznit volutpizzle, suscipizzle quizzle, fo shizzle mah nizzle fo rizzle, mah home g-dizzle vizzle, arcu. Pellentesque gizzle tortor. Dope erizzle. Yippiyo fo dolor dapibus turpis tempizzle dizzle. Mauris check it out nibh izzle gangster. Pizzle break yo neck, yall sheezy. Brizzle fo shizzle rhoncizzle nisi. In you son of a bizzle habitasse platea dictumst. Sure dapibizzle. Curabitizzle tellus urna, pretium eu, mattizzle ac, eleifend vitae, nunc. Dang suscipizzle. Integer semper things fizzle purizzle." ["post_title"]=> string(37) "Prostatectomia Radical Laparoscópica" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(36) "prostatectomia-radical-laparoscopica" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2013-03-13 13:12:58" ["post_modified_gmt"]=> string(19) "2013-03-13 13:12:58" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(55) "http://localhost:8888/?post_type=procedimento&p=19" ["menu_order"]=> int(0) ["post_type"]=> string(12) "procedimento" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } ["queried_object"]=> object(WP_Post)#226 (24) { ["ID"]=> int(19) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2013-03-12 13:51:38" ["post_date_gmt"]=> string(19) "2013-03-12 13:51:38" ["post_content"]=> string(601) "Lorizzle ipsum dolizzle ma nizzle amizzle, izzle adipiscing dope. Nullam sapizzle velizzle, shizznit volutpizzle, suscipizzle quizzle, fo shizzle mah nizzle fo rizzle, mah home g-dizzle vizzle, arcu. Pellentesque gizzle tortor. Dope erizzle. Yippiyo fo dolor dapibus turpis tempizzle dizzle. Mauris check it out nibh izzle gangster. Pizzle break yo neck, yall sheezy. Brizzle fo shizzle rhoncizzle nisi. In you son of a bizzle habitasse platea dictumst. Sure dapibizzle. Curabitizzle tellus urna, pretium eu, mattizzle ac, eleifend vitae, nunc. Dang suscipizzle. Integer semper things fizzle purizzle." ["post_title"]=> string(37) "Prostatectomia Radical Laparoscópica" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(36) "prostatectomia-radical-laparoscopica" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2013-03-13 13:12:58" ["post_modified_gmt"]=> string(19) "2013-03-13 13:12:58" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(55) "http://localhost:8888/?post_type=procedimento&p=19" ["menu_order"]=> int(0) ["post_type"]=> string(12) "procedimento" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } ["queried_object_id"]=> int(19) }
share|improve this question

1 Answer 1

Try this loop. you need to use the template tag the_permalink() to get the link to the single items.

As well as using the WP_Query class to grab the posts you want. The current query below will get the latest 10 published procedimentos posts. If you want to change the amount of posts or anything like that you can see the argument to use for WP_Query() here .

$procedimentos_posts = new WP_Query( array(
    'post_type' => 'procedimentos',
    'post_status' => 'publish'
));
if($procedimentos_posts->have_posts()) :
    while($procedimentos_posts->have_posts()) : $procedimentos_posts->the_post();
        echo '<a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
        the_content();
    endwhile;
endif;
wp_reset_postdata();
share|improve this answer
1  
You might want to change your post_type from "procedimentos" to just "procedimento". That way you could register the slug for "has_archive" as "procedimentos", and the single pages slugs would be "procedimento". The reason for this is how the url looks on the frontend. Your archive would be "sample.com/procedimentos/"; and a single would be "sample.com/procedimento/example/"; –  Warwick Mar 12 '13 at 13:39
    
Thank you for the quick reply, Warwick. I followed your suggestions, but I still only retrieve the top list post, no matter on which list item I click. –  lun8 Mar 12 '13 at 14:05
    
I have updated my answer, I think this is what you are looking for. –  Warwick Mar 12 '13 at 15:15
    
+1 for suggesting singular post type names. Anything else is bad practice. –  Johannes Pille Mar 12 '13 at 15:40
    
Hi guys. Thank you so much for your concern. Warwick, I tested the singular post type name, it really makes sense, but it didn't change the "same post for all permalinks calls" situation. Johannes, I'm pretty sure you're right, but I didn't get your loop to work. I am using a loop that gets the permalinks list. It works. The issue is that each item is linking to the same last/top post of the list when it's called by the single-procedimento. Therefore I suppose the single-procedimento loop is wrong, or the /%category%/%postname%/ permastructure is wrong or something. Got to figure it out(sob). –  lun8 Mar 12 '13 at 17:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.