• Hello,

    this is my export function:

    <?php if ($post_ids) {
    		global $wp_query;
    		$wp_query->in_the_loop = true;  // Fake being in the loop.
    		// fetch 20 posts at a time rather than loading the entire table into memory
    		while ( $next_posts = array_splice($post_ids, 0, 20) ) {
    			$where = "WHERE ID IN (".join(',', $next_posts).")";
    			$posts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'heberg' ORDER BY wpostmeta.meta_value DESC");
    				foreach ($posts as $post) {
    			// Don't export revisions.  They bloat the export.
    			if ( 'revision' == $post->post_type )
    				continue;
    			setup_postdata($post); ?>

    i would like to make the posts order by category ID, how to do that?

    bye

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter csseur3

    (@csseur3)

    oOups, i have a problem with my function: the posts are 5 times re-listed, why? 🙁

    Thread Starter csseur3

    (@csseur3)

    http://pastebin.com/m1be645a2 this is my entire function

    Trick is to get your categories with get_categories, then for each category then get/display the posts for each category. This examle prints a category title on each new category that you may not want…

    <?php
    $cat_args=array(
      'orderby' => 'ID',
      'order' => 'ASC'
       );
    $categories=get_categories($cat_args);
      foreach($categories as $category) {
        $args=array(
          'showposts' => -1,
          'category__in' => array($category->term_id),
          'caller_get_posts'=>1
        );
        $posts=get_posts($args);
          if ($posts) {
            echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
            foreach($posts as $post) {
              setup_postdata($post); ?>
              <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
              <?php
            } // foreach($posts
          } // if ($posts
        } // foreach($categories
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Order by category ID, not by post date’ is closed to new replies.