Support » Fixing WordPress » Sorting Product Pages

  • Hi guys,

    Long time troll. First time poster. Apologies if there is a thread for this. I’m working on a website for a friend and trying to get the product pages to sort alphabetically. I’ve tried using codes provided in other threads but to no avail.

    I want these products to sort alphabetically in ascending order (I.E: 240, 260, 300, 400, Cyclone, etc).

        function getParents($id) {
    	    global $wpdb;
    	    $posts_table = $wpdb->prefix . "posts";
    	    $parent_id = $wpdb->get_var("SELECT post_parent FROM $posts_table WHERE ID=$id");
    	    if($parent_id == 0) return '';
    	    $parent = get_post($parent_id);
    	    return getParents($parent_id) . '<a href="'. get_permalink($parent_id) .
    	    	"\" title=\"$parent->post_title\">$parent->post_title</a> > ";
    	<!-- LOOP -->
    <?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    				<h2><?php global $post; echo getParents($post->ID); ?>
    						   <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    		<!-- Display Subpages & Products -->
    				<ul id="productlist">
    				$children = get_children("post_type=page&post_parent=$post->ID&order=ASC");
    				foreach ($children as $child):
    						<a href="<?php echo get_permalink($child->ID) ?>" title="<?php echo $child->post_title ?>">
    						<img src="<?php echo get_post_meta($child->ID, "Product Image", true) ?>" />
    						<span><?php echo $child->post_title ?></span></a>
    				<?php endforeach; ?>
    		<?php endwhile; ?>
    	<?php else : ?>

    Any help would be much appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • replace following line

    $children = get_children("post_type=page&post_parent=$post->ID&order=ASC");


    $children = get_posts("numberposts=-1&post_type=page&post_parent=$post->ID&orderby=title&order=ASC");

    Thank you! Fixed straight away!

    Hi Dalla,
    Could you help me to do product pages like yours please ?
    Are you using any plug-in ?

    Hello, Dalla, Zeronex, Champwarez.

    I’m in the same boat. It seems so illogical that products do not sort by Name in ascending alpha-order.

    How did you work this solution? I tried to find code that matched what you’ve shown and nothing seems to match.


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sorting Product Pages’ is closed to new replies.