Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 views
in Technique[技术] by (71.8m points)

wordpress - Elementor Custom Query Orderby Custom Radio Field

Hello Im trying to order by posts (if possible) with the Elementor Custom Query Filter. I've created an advanced custom field that is a radio button that key is "has_images" and then given a radio button either a Yes or No option. The default is "No" and when I add images I change this to Yes. Im trying to have orderby show my custom post type "vehicles" with images first then those with default placeholder ( custom field no).

The query I've come up with

add_action( 'elementor/query/jet-smart-filters', function( $query ) {
    // Here we set the query to fetch posts with
    // ordered by post meta
    $query->set( 'meta_key', 'has_images' );
    $query->set( 'orderby', 'meta_value_num' ); // for numeric meta use `meta_value_num` instead of `meta_value`
    $query->set( 'order', 'ASC' ); // ordering
} );

I've tried meta_value_num and meta_value but this query only seems to show the posts with the radio button changed to yes.

Can this be done with Elementor Query?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...