• Looking through the Codex and Google and haven’t come up with an answer, so I figured posting here might help.

    Is it possible to use wp_list_pages with a sort_column of a custom field?

    I have a custom post type called Makers. The Title is the person’s full name. However, I want to display this in alphabetical order by last name. I created a custom field called sort_name with the last name (or first word of business name for the Makers it applies to). I’m listing all Makers in the sidebar and just need to get alphabetical by last name.

    Since a few users will be working on this that aren’t great with anything technological, I don’t want to use manual sort order.

    Any ideas?

    Thanks!

    – Matt

Viewing 1 replies (of 1 total)
  • Thread Starter Matt Banks

    (@mjbanks)

    Decided to use WP_query and just check the post/page ID and add a CSS class:

    <?php
    	// Create a new instance, Query Makers Post Type sorted by maker_sort_name
    	$second_query = new WP_Query( 'post_type=maker&meta_key=maker_sort_name&orderby=meta_value&order=ASC&posts_per_page=-1' );
    	$current_ID = get_the_ID();
    
    	if ( $second_query->have_posts() ) {
    		// The Loop
    		while( $second_query->have_posts() ) : $second_query->the_post(); ?>
    			<?php
    				$link_ID = get_the_ID();
    			?>
    			<li<?php if ( $current_ID == $link_ID ) { echo " class='current_page_item'"; } ?>><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    		<?php endwhile;
    	}
    
    	else { ?>
    		<li>No Makers found.</li>
    	<?php } ?>
    
    	<?php wp_reset_postdata(); ?>
Viewing 1 replies (of 1 total)
  • The topic ‘wp_list_pages Sort by Custom Field?’ is closed to new replies.