0

I need some help

I want to list all post from a meta_key, order by meta_value in ASC order All this in 1 toogle jquery.

I've this:

<div id="box-temp" class="gray-shadow">
<!-- First Loop -->
        <h3 class="titulo-temp"> NUMBER OF FIRST LOOP </h3>
        <hr>
            <ul class="items-temp">
            <?php query_posts('meta_key=numeroepisodio&orderby=meta_value&order=ASC'); ?>
            <?php while (have_posts()) : the_post(); ?>
                <?php $numeroepisodio = get_post_meta($post->ID, 'numeroepisodio',true);?>
                <a href="<?php the_permalink() ?>"><li>
                <strong><?php  echo 'Episodio '.$numeroepisodio; ?>:</strong> <?php the_title(); ?> <img src="//cdn.enlatino.net/img/play.png" class="img-play">
                </li></a>
            <?php endwhile; ?>
            <hr class="no-top">
            </ul>
    <!-- Second Loop -->
       <h3 class="titulo-temp"> NUMBER OF SECOND LOOP </h3>
      <hr>
            <ul id="items-temp1" class="items-temp">
            <?php query_posts('meta_key=numeroepisodio&orderby=meta_value&order=ASC'); ?>
            <?php while (have_posts()) : the_post(); ?>
                <?php $numeroepisodio = get_post_meta($post->ID, 'numeroepisodio',true);?>
                <a href="<?php the_permalink() ?>"><li>
                <strong><?php  echo 'Episodio '.$numeroepisodio; ?>:</strong> <?php the_title(); ?> <img src="//cdn.enlatino.net/img/play.png" class="img-play">
                </li></a>
            <?php endwhile; ?>
            <hr class="no-top">
            </ul>
        </div><!-- Fin Box-Temp -->

What i want to show:

All loops: http://prntscr.com/62fn5l

The loop in action: http://prntscr.com/62fmvv

Its advisable to save the post in a category to show and control this better?

Sorry for my english i'm from Argentina.

Thanks to read.

7
  • How are your posts related to each other? e.g. For what kind of items are your seasons (e.g. taxonomies or post types) and how do they relate to each episode that you want to show under it? This will determine how the logic should be approached to do what you are attempting.
    – Privateer
    Commented Feb 8, 2015 at 3:51
  • I create page templates where i show all seasons and episodes from a serie. Serie 1 -> 5 Temporadas -> 25 episodes per season All seasons en 1 toggle I don't create a post type or taxonomies, what you recommend?
    – Ferrmolina
    Commented Feb 8, 2015 at 3:54
  • Are you using a custom post type? Or are these pages (hierarchical) so that each episode is a child of a temporada which is a child of a series? (Basically, how are they related in wordpress? )
    – Privateer
    Commented Feb 8, 2015 at 4:06
  • They aren't related. I only create a page, and inside the loops, order by meta_key I going to create the custom taxonomies, and the loops order by terms of taxonomies, its ok?
    – Ferrmolina
    Commented Feb 8, 2015 at 4:16
  • 1
    You have two really big issues here, never ever use query_posts, it will break a lot of things on your page. If you have to use a custom query, use WP_Query instead. Also, you have to reset every custom loop if you setup the loop or postdata. Go back, rewrite your code to use WP_Query and add wp_reset_postdata() after every loop Commented Feb 8, 2015 at 6:15

1 Answer 1

1

Based on the comments, you should be able to do something like the following:

  1. Create a custom taxonomy to hold your Temporadora items in (e.g. Temporadora 1)
  2. Create a custom post type to hold your episodes
  3. Create a relationship between the two

From there, it should be a matter of doing something like the following:

$args = array(
    'orderby' => 'name',
    'order' => 'ASC',
    'hide_empty' => true
);
$temporadoras = get_terms('temporadora', $args);
if ( is_wp_error( $temporadoras ) ) {
   echo "<p>Error!</p><pre>" . print_r( $temporadoras, true ) . "</pre>";
} else {
   foreach ( $temporadoras as $temporadora ) {
      $post_args = array(
          'post_type' => 'episode',
          'tax_query' => array(
              array(
                 'taxonomy' => 'temporadora',
                 'terms' => $temporadora->term_id
              )
          ),
          'posts_per_page' => -1,
          'orderby' => 'name',
          'order' => 'ASC'
      );
      $post_list = new WP_Query( $post_args );
      if ( $post_list->have_posts() ) {
          while ( $post_list->have_posts() ) {
             $episode = $post_list->next_post();
             echo "<p>Found Posts:</p><pre>" . print_r($episode, true) . "</pre>";
          }
      } else {
          echo "<p>None found for temporadora:</p><pre>" . print_r($temporadora, true) . "</pre>";
      }
   }
}

That should grab all of the temporadora taxonomy items in order then, for each of them, grab and print out each related episode.

For reference:

3
  • Can help me? I can get the post from taxonomy: temporada, with post type: episodio BUT, this is from an one "serie", i don't know if you understand me. I create a new taxonomy: "Serie". How to build a loop with filter Series, post type episodio and order by term temporada? I've this loop now: pastebin.com/fPNX9fCj This return the loop correctly, but when i create another page with same information but diferent 'serie' taxonomy, its return same content for all.
    – Ferrmolina
    Commented Feb 8, 2015 at 12:10
  • 2 images for you understandme better: prntscr.com/62j7pa prntscr.com/62j76w
    – Ferrmolina
    Commented Feb 8, 2015 at 12:15
  • Thanks. I'll take a look this evening when I have some free time and see if I can help you wrap this up.
    – Privateer
    Commented Feb 9, 2015 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.