Dear theamazingaustin
If you want to use orderby using custom field, you need add this custom field using meta_key and fill orderby by meta_value.
More: WP_Query Orderby Parameters.
If you want to use post_title just fill orderby by title.
Regards
Marcin
Thanks for your help Marcin,
I’ve tried it this way as well, but reverted to test it out a second time. Here is my code now, still no luck. Is this the correct way to implement the Types custom field into an argument?
Thanks!
-Austin
$args = array(
'posts_per_page' => 100,
'post_type' => 'workshop-date',
'meta_key' => types_render_field("date", array("output"=>"raw")),
'orderby' => 'meta_value',
'order' => 'ASC');
Here’s a complete summary of my code, I’m really stumped and hoping someone might have a word of advice. There is no sorting at all happening when I use this, but orderby => using worpress variables (ex: title, date, etc) works just fine…
Thank you in advanced for your time!!! 🙂
<?php
// Set arguments for the query in a php array.
$args = array(
'posts_per_page' => 100,
'post_type' => 'workshop-date',
'meta_key' => types_render_field("date", array("output"=>"raw")),
'orderby' => 'meta_value',
'order' => 'ASC');
$query = new wp_query( $args );
//While you still have posts (haven't displayed the last one) - then display it!
if ( $query -> have_posts() ) : while ( $query -> have_posts() ) : $query -> the_post();
?>
//HTML Output of posts here
<?php
endwhile;
else:
?>
<p>There are no dates to display.</p>
<?php endif; ?>
After hours of time, I’ve figured out issues, and the code is below.
The line:
'meta_key' => types_render_field("date", array("output"=>"raw"))'
Is not valid, and the Types plugin variable must be used in this way:
'meta_key' => 'wpcf-date',
Wow. That was simple.