• Have a query, and am trying to sort via a custom field but it’s not working. It doesn’t change / sort anything at all.

    $args = array(
    		'posts_per_page' => 100,
    		'post_type' => 'workshop-date',
    		'orderby' => types_render_field("title", array("output"=>"raw")),
    		'order' => 'ASC');

    I eventually want to replace title with a date field, but am using the title for simplicity’s sake at the moment.

    Replaceing this with ‘title’ works fine, so I know it’s not a sorting issue elsewhere in the code…

    Thanks!

    https://www.ads-software.com/plugins/types/

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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

    Thread Starter theamazingaustin

    (@theamazingaustin)

    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');
    Thread Starter theamazingaustin

    (@theamazingaustin)

    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; ?>
    Thread Starter theamazingaustin

    (@theamazingaustin)

    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.

    info2grow

    (@info2grow)

    @theamazingaustin THANK YOU!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Orderby => types_render_field not working…’ is closed to new replies.