• Resolved adalsteinn

    (@adalsteinn)


    I am using a hierarchical custom post type for a magazine on my website. The idea is that each article of an issue will be published as a child post of the parent issue post. For example issue number 1 would be ‘issue 1’ and article number 1 of that issue would be ‘issue 1 -> article 1’. Article two would be ‘issue -> article 2’ and so on.

    My problem is with the table of contents. I want to list all posts of an issue with the issue post itself and with all of the single article posts. In that list I want to be able to use the post images (featured image) and check if a custom field exist in each post (that tells me if the post is open to everyone or just subscribers).

    Now I am using this code that lists the sibling post names and links:

    <?php
      if($post->post_parent)
      $children = wp_list_pages("post_type=tolublad&title_li=&child_of=".$post->post_parent."&echo=0");
      else
      $children = wp_list_pages("post_type=tolublad&title_li=&child_of=".$post->ID."&echo=0");
      if ($children) { ?>
      <ul>
    	<h4>Í þessu tölublaði:</h4>
      <?php echo $children; ?>
      </ul>
     <?php } ?>

    Is there a way for me to set up a custom query that calls siblings of the current post? Or can I call the featured image and check a custom field with wp_list_pages function?

    You can see my site in action at skastrik.is but be aware that the site is in icelandic. You can see the sibling list if you click “Efnisyfirlit” in the top left corner.

Viewing 1 replies (of 1 total)
  • Thread Starter adalsteinn

    (@adalsteinn)

    The solution I found was simply calling the custom field with wp_list_pages. The code I used:

    <?php
       if($post->post_parent)
       $pages = get_pages('post_type=tolublad&title_li=&child_of='.$post->post_parent.'&sort_column=post_date&sort_order=asc&echo=0');
       else
       $pages = get_pages('post_type=tolublad&title_li=&child_of='.$post->ID.'&sort_column=post_date&sort_order=asc&echo=0');
       $count = 0;
       foreach($pages as $page)
       {
       $content = $page->post_content;
       if(!$content)
       continue;
       $content = apply_filters('the_content', $content); ?>
    
       <li><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a><?php if( get_post_meta($page->ID, 'subscribers', true) ) { ?><img src="<?php bloginfo('stylesheet_directory'); ?>/images/lock.png" class="lock" /><?php } ?></li>
    <?php } ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Post Type Siblings’ is closed to new replies.