WordPress.org

Ready to get started?Download WordPress

Forums

The Events Calendar
[resolved] OrderBy=TitleO&Order=ASC Isn't Working (10 posts)

  1. WebDevB
    Member
    Posted 1 year ago #

    Hi Guys,

    Im running a custom query on my event posts and for some reason it doesn't want to sort it by alphabetical?

    Here is the code:

    `<?php query_posts('tribe_events_cat=my-group&post_type=tribe_events&showposts=100&orderby=title&order=ASC');if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

    Can anyone shed any light on this?

    http://wordpress.org/extend/plugins/the-events-calendar/

  2. roblagatta
    Modern Tribe Support
    Plugin Author

    Posted 1 year ago #

    Hey, WebDevB. Not sure about this one myself but I can certainly have Jonah from our team take a look and see if he can identify an issue with this query. Stay tuned!

  3. jonahcoyote
    Member
    Posted 1 year ago #

    Hey WebDevB,

    First, don't use query_posts(), use WP_Query instead in almost all cases for custom queries. You can read more about this all over the internet, but here's one good post on the subject: http://www.wpmayor.com/articles/when-use-wp_query-vs-query_posts-vs-get_posts/

    So, first switch up your query to use WP_Query.

    Next, 'tribe_events_cat' is not an argument you can pass in - i.e. there is no argument for the WP_Query function for this. You'll need to use tax_query instead. Here's an example of a custom WP_Query with tax_query:

    <ul>
    <?php
    
    $args = array(
        'post_status'=>'publish',
        'post_type'=>'tribe_events',
        'posts_per_page'=>100,
        'tax_query', array(
    	array(
    		'taxonomy' => TribeEvents::TAXONOMY,
    		'field' => 'slug',
    		'terms' => array('my-group'),
    		'operator' => 'IN'
    	)
        ),
        'orderby'=>'title',
        'order'=>'ASC'
    );
    $get_posts = null;
    $get_posts = new WP_Query();
    
    $get_posts->query($args);
    if($get_posts->have_posts()) : while($get_posts->have_posts()) : $get_posts->the_post(); ?>
    
      <li>
        <?php the_title(); ?>
      </li>
    
    <?php
      endwhile;
      endif;
      wp_reset_query();
    ?>
    </ul>

    Try that and let me know how it works for you.

    - Jonah

  4. WebDevB
    Member
    Posted 1 year ago #

    Hi Jonah,

    I've tried that but it doesn't seem to work very well.

    Here is the code:

    <ul class="generic">
    			<?php
    
    			$args = array(
    			    'post_status'=>'publish',
    			    'post_type'=>'tribe_events',
    			    'posts_per_page'=>100,
    			    'tax_query', array(
    				array(
    					'taxonomy' => TribeEvents::TAXONOMY,
    					'field' => 'slug',
    					'terms' => array('site-specific-groups'),
    					'operator' => 'IN'
    				)
    			    ),
    			    'orderby'=>'title',
    			    'order'=>'ASC'
    			);
    			$get_posts = null;
    			$get_posts = new WP_Query();
    
    			$get_posts->query($args);
    			if($get_posts->have_posts()) : while($get_posts->have_posts()) : $get_posts->the_post(); ?>
    
    			  <li>
    			    <?php the_title(); ?>
    			  </li>
    
    			<?php
    			  endwhile;
    			  endif;
    			  wp_reset_query();
    			?>
    		</ul>

    It show more than the groups that are assigned to that category and it doesn't sort it in alphabetical order...

    Any other ideas?

  5. jonahcoyote
    Member
    Posted 1 year ago #

    Hey WebDevB,

    Try this instead:

    <ul class="generic">
          <?php
    
          $args = array(
              'post_status'=>'publish',
              'post_type'=>array(TribeEvents::POSTTYPE),
              'posts_per_page'=>100,
              'tax_query', array(
                array(
                  'taxonomy' => TribeEvents::TAXONOMY,
                  'field' => 'slug',
                  'terms' => array('site-specific-groups'),
                  'operator' => 'IN'
                )
              ),
              'orderby'=>'title',
              'order'=>'ASC'
          );
          $get_posts = null;
          $get_posts = new WP_Query();
    
          $get_posts->query($args);
          if($get_posts->have_posts()) : while($get_posts->have_posts()) : $get_posts->the_post(); ?>
    
            <li>
              <?php the_title(); ?>
            </li>
    
          <?php
            endwhile;
            endif;
            wp_reset_query();
          ?>
        </ul>

    Turns out the query will ignore certain arguments if the post_type is not set this other way.

    - Jonah

  6. WebDevB
    Member
    Posted 1 year ago #

    Hi Jonah,

    That works but it list all the posts not just the ones within that category...

    Any ideas?

  7. jonahcoyote
    Member
    Posted 1 year ago #

    Hey WebDevB,

    There was a syntax error, sorry about that. Try this:

    <ul class="generic">
          <?php
    
          $args = array(
              'post_status'=>'publish',
              'post_type'=>array(TribeEvents::POSTTYPE),
              'posts_per_page'=>100,
              'tax_query' => array(
                array(
                  'taxonomy' => TribeEvents::TAXONOMY,
                  'field' => 'slug',
                  'terms' => 'site-specific-groups',
                  'operator' => 'IN'
                )
              ),
              'orderby'=>'title',
              'order'=>'ASC'
          );
          $get_posts = null;
          $get_posts = new WP_Query();
    
          $get_posts->query($args);
          if($get_posts->have_posts()) : while($get_posts->have_posts()) : $get_posts->the_post(); ?>
    
            <li>
              <?php the_title(); ?>
            </li>
    
          <?php
            endwhile;
            endif;
            wp_reset_query();
          ?>
        </ul>

    - Jonah

  8. WebDevB
    Member
    Posted 1 year ago #

    Fantastic Jonah!!!

    Thanks alot for your help mate.

    Thanks,

    Scott

  9. WebDevB
    Member
    Posted 1 year ago #

    Thanks again.

  10. jonahcoyote
    Member
    Posted 1 year ago #

    No problem Scott, let me know if you need anything else.

    - Jonah

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.