- This topic has 7 replies, 3 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
January 16, 2023 at 2:44 pm #2498102
Royal Rangers
Hi, I have a custom post type for Events and using ACF for a date field for the event.
I try this code:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { // apply filter if loop has class: my-order if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-order' ) !== false ) { // merge meta_key my-custom-field into query return array_merge( $query_args, array( 'meta_key' => 'datum', 'orderby' => 'meta_value', 'order' => 'DESC', ) ); } return $query_args; }, 10, 2 );I trying this https://generatepress.com/forums/topic/query-loop-use-acf-date-field-as-order-by-parameter/#post-2405953.
Can you help me?
January 16, 2023 at 5:54 pm #2498228Fernando Customer Support
Hi Jan,
Yes, we can try to help.
Can you try this snippet instead?:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { // apply filter if loop has class: my-order if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-order' ) !== false ) { $query_args['orderby'] = 'meta_value'; $query_args['meta_key'] = 'datum'; $query_args['order'] = 'DESC'; } return $query_args; }, 10, 2 );Let us know how it goes.
January 16, 2023 at 9:57 pm #2498378Royal Rangers
Code replaced but doesn´t work. The date field is in d/m/Y format. What mean meta_value? I don’t have it set Order by in Query loop and I don’t see any option for ACF there.
January 16, 2023 at 10:28 pm #2498393Fernando Customer Support
meta_valueis the value of your custom meta fielddatum.Ordering by custom meta fields isn’t available yet but it is planned for a future update.
Can you take a screenshot of your ACF field settings for reference?
You may use the Private Information field for this: https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information
January 17, 2023 at 3:04 am #2498596Royal Rangers
I found a bug in setting. It works now. Is possible view custom field date in Gutenberg block with ACF free?
January 17, 2023 at 5:22 am #2498739David
StaffCustomer SupportHi there,
yes, if you add a GenerateBlocks Block, eg. a Headline block, and enable its Dynamic Data, you can set the Content source to
Post Metaand in the field provided add your ACF Field name.January 17, 2023 at 5:46 am #2498761Royal Rangers
It works. Thanks.
January 17, 2023 at 7:01 am #2498850David
StaffCustomer SupportGlad to hear that
-
AuthorPosts
- You must be logged in to reply to this topic.