Support » Developing with WordPress » Help listing child posts!

  • Resolved theotherdon

    (@theotherdon)


    I have created a hierarchical custom post type, and am trying to use the following function to list list links to the child posts on their parent.

    It is working, except that the children are listed in reverse-alphabetical order. I sure would appreciate any suggestions to get them listed in the opposite order! TIA

    function sb_child_page_menu( $current_parent ) {
    
    // Display Subpages on the parent 
    
    //	if(wp_get_post_parent_id($current_parent)) {
    //		$parent_ID = wp_get_post_parent_id( $current_parent );
    //	} else {
    		$parent_ID = $current_parent;
    //	}
    
    // Get the Childpages / Subpages using get_children function
    
    	$arg = array(
    		'post_parent' => $parent_ID,
    	);
    
    	$childrens = get_children( $arg );
    
    	if( !empty($childrens) ) {
    		echo '<div id="child_regions"><span class="lable1">Child regions:</span><br /><ul class="child-links">';
    		foreach ( $childrens as $children ) {
    			echo '<li><a href="'.get_permalink($children->ID).'">'.$children->post_title.'</a></li>';
    		}
    		echo '</ul></div>';
    	}
    }
    
    • This topic was modified 1 week, 6 days ago by theotherdon.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.