Support » Fixing WordPress » Post Order of a Custom Post Type Using a custom meta box

  • I created a custom post type and custom taxonomy. Each post type is used to display an image for an infinite carousel. I have everything working correctly in terms of displaying correctly and pulling the correct posts. However I would like to be able to display the post in different orders depending upon the # given in the custom meta box field and the template page calling that query. Below is an example of the loop code that I have been using

    <!-- BEGIN .infiniteCarousel -->
     <div class="infiniteCarousel">
      <!-- BEGIN .wrapper -->
       <div class="wrapper">
          global $post;
          $featuredPosts = new WP_Query(array('post_type' => 'slider', 'crs_slider' => 'crs-safety-slider', 'posts_per_page' => '-1', 'meta_key' => $custom['safety_order'][0], 'orderby' => 'meta_value_num', 'order' => 'DESC')); 
          while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); 
           $custom = get_post_custom($post->ID);
           $small_image = $custom["small_image"][0];
           $large_image = $custom["large_image"][0];
           $image_title = $custom["image_title"][0];
           $image_alt = $custom["image_alt"][0]; ?>
            <a rel="prettyPhoto[carousel]" href="<?php echo $large_image; ?>" class="slider-item">
             <img title="<?php echo $image_title; ?>" alt="<?php echo $image_alt; ?>" src="<?php echo $small_image; ?>" />
          <?php endwhile; ?>
        <!-- END .wrapper -->
       <!-- END .infiniteCarousel -->
Viewing 1 replies (of 1 total)
  • To be a little more specific from above, the part of the code that I am having trouble with is this:

    $featuredPosts = new WP_Query(array('post_type' => 'slider', 'crs_slider' => 'crs-safety-slider', 'posts_per_page' => '-1', 'meta_key' => $custom['safety_order'][0], 'orderby' => 'meta_value_num', 'order' => 'DESC'

    Like I said, I am having no trouble pulling the post I need it is just the order they display in. I would just use the ID (and add that to my custom post type) but I need more than one options. This image could show up in multiple carousels (depending upon the custom taxonomy categories it is in) and depending upon what carousel it is being displayed in I have a custom meta box field that I would like to use to determine the order, in the above case the

    'meta_key' => $custom['safety_order'][0]

    is the custom meta field I would like to use for this slider.

    I just noticed something, I set $custom with

    $custom = get_post_custom($post->ID);

    but that is inside the loop, and I am trying to use $custom before setting it. Does anybody have any suggestions.


Viewing 1 replies (of 1 total)
  • The topic ‘Post Order of a Custom Post Type Using a custom meta box’ is closed to new replies.