Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been working on this issue for several hours now and I'm stumped. The following query refuses to accept any orderby directive. NOTE: This is running on a single-cpt.php page within the normal WP Loop:

<?php $args = array(
  'orderby' => 'title',
      'order' => 'ASC',
  'suppress_filters' => true,
  'nopaging' => true,
  'connected_type' => 'directory_to_projects',
  'connected_items' => get_queried_object_id(),
);

$new_connected = new WP_Query($args);

// Display connected posts
if ( $new_connected->have_posts() ) { ?>

    <h3>Projects</h3>
    <ul>
        <?php while ( $new_connected->have_posts() ) : $new_connected->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; 
        endif;
        wp_reset_postdata(); ?>
    </ul>
<?php } ?>

I've confirmed I'm not running any page- or post-ordering plugins that might interfere with 'orderby'. Switching 'orderby' to something else (name, date, meta_value, you name it) has no effect whatsoever.

UPDATE: Actually, no parameters for wp_query are working at all. I tried adding 'posts_per_page' => 2, and that had no effect either. Must be a posts2posts thing but I believe support for that plugin has been discontinued. :( Anyone ever run into this?

Any ideas? Thanks so much for your help!

share|improve this question
    
If you deactivate the Posts2posts plugin, does the query return the correct posts? –  Charles Clarkson Aug 14 '13 at 21:12

1 Answer 1

I don't have any experience with posts2posts, but to see the query that wp_query runs on your database, before your if statement, put echo $new_connected->request. Helped me a lot to debug wp_query when I couldn't find out which parameters weren't working. The output is the SQL query that will be performed on the DB. Therefor you can copy this query in phpmyadmin to see the results. Maybe it will help you gain more insight into the problem!

PS using 'orderby' => 'meta_value' requires 'meta_key' => 'your_metakey_name' else it doesn't know which key to get the value from to sort by.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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