Tagged: acf
-
AuthorPosts
-
November 6, 2017 at 4:47 pm #873150
Hey,
I like to sort my portfolio by a Custom Field (date). How can I use your code (above) to sort portfolio entries by MyCustomField?if(!function_exists('avia_custom_query_extension')) { function avia_custom_query_extension($query, $params) { global $avia_config; if(!empty($avia_config['avia_custom_query_options']['order'])) { $query['order'] = $avia_config['avia_custom_query_options']['order']; } if(!empty($avia_config['avia_custom_query_options']['orderby'])) { $query['orderby'] = $avia_config['avia_custom_query_options']['orderby']; } unset($avia_config['avia_custom_query_options']); return $query; } add_filter('avia_masonry_entries_query', 'avia_custom_query_extension', 10, 2); add_filter('avia_post_grid_query', 'avia_custom_query_extension', 10, 2); add_filter('avia_post_slide_query', 'avia_custom_query_extension', 10, 2); add_filter('avia_blog_post_query', 'avia_custom_query_extension', 10, 2); add_filter('avf_magazine_entries_query', 'avia_custom_query_extension', 10, 2); add_filter('avf_template_builder_shortcode_elements','avia_custom_query_options', 10, 1); function avia_custom_query_options($elements) { $allowed_elements = array('av_blog','av_masonry_entries','av_postslider','av_portfolio','av_magazine'); if(isset($_POST['params']['allowed']) && in_array($_POST['params']['allowed'], $allowed_elements)) { $elements[] = array( "name" => __("Custom Query Orderby",'avia_framework' ), "desc" => __("Set a custom query orderby value",'avia_framework' ), "id" => "orderby", "type" => "select", "std" => "", "subtype" => array( __('Default Order', 'avia_framework' ) =>'', __('Title', 'avia_framework' ) =>'title', __('Random', 'avia_framework' ) =>'rand', __('Date', 'avia_framework' ) =>'date', __('Author', 'avia_framework' ) =>'author', __('Name (Post Slug)', 'avia_framework' ) =>'name', __('Modified', 'avia_framework' ) =>'modified', __('Comment Count', 'avia_framework' ) =>'comment_count', __('Page Order', 'avia_framework' ) =>'menu_order') ); $elements[] = array( "name" => __("Custom Query Order",'avia_framework' ), "desc" => __("Set a custom query order",'avia_framework' ), "id" => "order", "type" => "select", "std" => "", "subtype" => array( __('Default Order', 'avia_framework' ) =>'', __('Ascending Order', 'avia_framework' ) =>'ASC', __('Descending Order', 'avia_framework' ) =>'DESC')); } return $elements; } add_filter('avf_template_builder_shortcode_meta', 'avia_custom_query_add_query_params_to_config', 10, 4); function avia_custom_query_add_query_params_to_config($meta, $atts, $content, $shortcodename) { global $avia_config; if(empty($avia_config['avia_custom_query_options'])) $avia_config['avia_custom_query_options'] = array(); if(!empty($atts['order'])) { $avia_config['avia_custom_query_options']['order'] = $atts['order']; } if(!empty($atts['orderby'])) { $avia_config['avia_custom_query_options']['orderby'] = $atts['orderby']; } return $meta; } }
November 6, 2017 at 4:54 pm #873155are you using a child-theme ?
Than put it in your functions.php of your child-theme.On edit mode of the alb element ( Masonry , Portfolio Grid, Magazine, Blog Posts … ) there will be an order option to choose
under custom css (if activated) there are
Custom Query Orderby
Custom Query Order- This reply was modified 7 years, 1 month ago by Guenni007.
November 6, 2017 at 8:55 pm #873336Hello Guenni007, thanks for answering. But my question is another.one: I don’t know how to cistomize this code for my ACF field?
I use a ACF Field for the Date of a Event and want to sort my Events by this date. Should I customize the code or should I think in another direction?
November 8, 2017 at 5:20 am #873993Hi,
I think that’s possible but you need to use the “meta_value” as the “orderby” paramater.
// https://codex.wordpress.org/Class_Reference/WP_Query // look for the Order & Orderby Parameters section
Please contact the plugin for more info.
Best regards,
IsmaelNovember 8, 2017 at 10:11 am #874084Good Morning Ismael,
yes it´s possible – I just don´t know how to put my ACF field[acf field="kursbeginn"]
into your “avia_custom_query_extension”?November 9, 2017 at 6:57 am #874456Hi,
We modified the code a bit. Please select “Meta Value” in the “Orderby” settings.
if(!function_exists('avia_custom_query_extension')) { function avia_custom_query_extension($query, $params) { global $avia_config; if(!empty($avia_config['avia_custom_query_options']['order'])) { $query['order'] = $avia_config['avia_custom_query_options']['order']; } if(!empty($avia_config['avia_custom_query_options']['orderby'])) { $query['orderby'] = $avia_config['avia_custom_query_options']['orderby']; if($avia_config['avia_custom_query_options']['orderby'] == 'meta_value') { $value = get_field( "kursbeginn" ); $query['meta_key'] => $value; } } unset($avia_config['avia_custom_query_options']); return $query; } add_filter('avia_masonry_entries_query', 'avia_custom_query_extension', 10, 2); add_filter('avia_post_grid_query', 'avia_custom_query_extension', 10, 2); add_filter('avia_post_slide_query', 'avia_custom_query_extension', 10, 2); add_filter('avia_blog_post_query', 'avia_custom_query_extension', 10, 2); add_filter('avf_magazine_entries_query', 'avia_custom_query_extension', 10, 2); add_filter('avf_template_builder_shortcode_elements','avia_custom_query_options', 10, 1); function avia_custom_query_options($elements) { $allowed_elements = array('av_blog','av_masonry_entries','av_postslider','av_portfolio','av_magazine'); if(isset($_POST['params']['allowed']) && in_array($_POST['params']['allowed'], $allowed_elements)) { $elements[] = array( "name" => __("Custom Query Orderby",'avia_framework' ), "desc" => __("Set a custom query orderby value",'avia_framework' ), "id" => "orderby", "type" => "select", "std" => "", "subtype" => array( __('Default Order', 'avia_framework' ) =>'', __('Title', 'avia_framework' ) =>'title', __('Random', 'avia_framework' ) =>'rand', __('Date', 'avia_framework' ) =>'date', __('Author', 'avia_framework' ) =>'author', __('Name (Post Slug)', 'avia_framework' ) =>'name', __('Modified', 'avia_framework' ) =>'modified', __('Comment Count', 'avia_framework' ) =>'comment_count', __('Page Order', 'avia_framework' ) =>'menu_order'), __('Meta Value', 'avia_framework' ) =>'meta_value') ); $elements[] = array( "name" => __("Custom Query Order",'avia_framework' ), "desc" => __("Set a custom query order",'avia_framework' ), "id" => "order", "type" => "select", "std" => "", "subtype" => array( __('Default Order', 'avia_framework' ) =>'', __('Ascending Order', 'avia_framework' ) =>'ASC', __('Descending Order', 'avia_framework' ) =>'DESC')); } return $elements; } add_filter('avf_template_builder_shortcode_meta', 'avia_custom_query_add_query_params_to_config', 10, 4); function avia_custom_query_add_query_params_to_config($meta, $atts, $content, $shortcodename) { global $avia_config; if(empty($avia_config['avia_custom_query_options'])) $avia_config['avia_custom_query_options'] = array(); if(!empty($atts['order'])) { $avia_config['avia_custom_query_options']['order'] = $atts['order']; } if(!empty($atts['orderby'])) { $avia_config['avia_custom_query_options']['orderby'] = $atts['orderby']; } return $meta; } }
Best regards,
IsmaelNovember 9, 2017 at 9:30 am #874563Good Morning early working Ismael – thanks for your work!
Only problem is a syntax error on the line
$query['meta_key'] => $value;
I´ve tried to figure it out for myself, without success. Can somebody please remove the syntax error?November 10, 2017 at 6:36 am #875019Hi,
My bad. It’s an invalid code. Please replace it with:
$query['meta_key'] = $value;
Best regards,
IsmaelNovember 10, 2017 at 10:20 am #875086… thanks, but it is still nort working. I´ve eliminated one more syntax error -see code above. Use “modified” in the Custom Query Orderby element.
But the order is still wrong!if(!function_exists('avia_custom_query_extension')) { function avia_custom_query_extension($query, $params) { global $avia_config; if(!empty($avia_config['avia_custom_query_options']['order'])) { $query['order'] = $avia_config['avia_custom_query_options']['order']; } if(!empty($avia_config['avia_custom_query_options']['orderby'])) { $query['orderby'] = $avia_config['avia_custom_query_options']['orderby']; if($avia_config['avia_custom_query_options']['orderby'] == 'meta_value') { $value = get_field( "kursbeginn" ); $query['meta_key'] = $value; } } unset($avia_config['avia_custom_query_options']); return $query; } add_filter('avia_masonry_entries_query', 'avia_custom_query_extension', 10, 2); add_filter('avia_post_grid_query', 'avia_custom_query_extension', 10, 2); add_filter('avia_post_slide_query', 'avia_custom_query_extension', 10, 2); add_filter('avia_blog_post_query', 'avia_custom_query_extension', 10, 2); add_filter('avf_magazine_entries_query', 'avia_custom_query_extension', 10, 2); add_filter('avf_template_builder_shortcode_elements','avia_custom_query_options', 10, 1); function avia_custom_query_options($elements) { $allowed_elements = array('av_blog','av_masonry_entries','av_postslider','av_portfolio','av_magazine'); if(isset($_POST['params']['allowed']) && in_array($_POST['params']['allowed'], $allowed_elements)) { $elements[] = array( "name" => __("Custom Query Orderby",'avia_framework' ), "desc" => __("Set a custom query orderby value",'avia_framework' ), "id" => "orderby", "type" => "select", "std" => "", "subtype" => array( __('Default Order', 'avia_framework' ) =>'', __('Title', 'avia_framework' ) =>'title', __('Random', 'avia_framework' ) =>'rand', __('Date', 'avia_framework' ) =>'date', __('Author', 'avia_framework' ) =>'author', __('Name (Post Slug)', 'avia_framework' ) =>'name', __('Modified', 'avia_framework' ) =>'modified', __('Comment Count', 'avia_framework' ) =>'comment_count', __('Page Order', 'avia_framework' ) =>'menu_order'), __('Meta Value', 'avia_framework' ) =>'meta_value') ; $elements[] = array( "name" => __("Custom Query Order",'avia_framework' ), "desc" => __("Set a custom query order",'avia_framework' ), "id" => "order", "type" => "select", "std" => "", "subtype" => array( __('Default Order', 'avia_framework' ) =>'', __('Ascending Order', 'avia_framework' ) =>'ASC', __('Descending Order', 'avia_framework' ) =>'DESC')); } return $elements; } add_filter('avf_template_builder_shortcode_meta', 'avia_custom_query_add_query_params_to_config', 10, 4); function avia_custom_query_add_query_params_to_config($meta, $atts, $content, $shortcodename) { global $avia_config; if(empty($avia_config['avia_custom_query_options'])) $avia_config['avia_custom_query_options'] = array(); if(!empty($atts['order'])) { $avia_config['avia_custom_query_options']['order'] = $atts['order']; } if(!empty($atts['orderby'])) { $avia_config['avia_custom_query_options']['orderby'] = $atts['orderby']; } return $meta; } }
November 13, 2017 at 4:34 am #875930Hi,
Could you provide an example of the “kursbeginn” custom field value?
Best regards,
IsmaelNovember 13, 2017 at 9:31 am #875997Hi Ismael, don´t know what you exactly asking for? My events should ordered by the date of the custom field “kursbeginn”. This should look like this:
[kursbeginn= 02.01.18 ] event#7
[kursbeginn= 05.02.18 ] event#4
[kursbeginn= 22.03.18 ] event#5… the field type of “kursbeginn” is a date picker, therefore the value is a date. Does this help? Or do you need something else? If you want to have a closer look I give you admin access (see private content)
November 14, 2017 at 8:04 am #876486Hi!
Where did you add the filter? The functions.php file is blank. Please try this code instead.
add_filter('avia_masonry_entries_query', 'avia_masonry_entries_query_mod', 10, 2); function avia_masonry_entries_query_mod($query, $params) { if(is_page(array(724, 3661, 3662))) { $value = get_field( "kursbeginn" ); $query['meta_query'] = array( array( 'key' => 'kursbeginn', 'value' => strtotime($value), 'compare' => '<', 'type' => 'DATE' ) ); $query['meta_key'] = 'kursbeginn'; } return $query; }
The code will adjust the masonry query directly so you don’t need to set the Order and Orderby settings.
Regards,
IsmaelNovember 14, 2017 at 9:53 am #876513… no, the function.php isn´t blank (see Child-Theme)! ANYWAY thanks for your code – but it´s not working.
I put your Code into my function.php but nothing change at all – the order of my events is exactly the same. What can I do?
November 16, 2017 at 4:14 am #877337Hi,
The functions.php file is blank. I can’t see any code in it. Please check the screenshot.
Best regards,
IsmaelNovember 16, 2017 at 9:36 am #877416OK, I see. Useaally I don´t use the WordPress editor. I edit the function.php via FTP. Do you know why function.php code not show up in the wordpress editor?
Anyway I´ve put your code into the functions.php via wordpress editor. The result is:
1) Events order is still the same – it´s not working
2) The event date is disappearing. Killed by the function?Sorry, but your support doesn´t really help. I have to wait more than a day for an answer and instead of solving problems, more problems coming up (editor function.php not showing). If you not really want help me, please feel free to say no. This is better than waste my (and also yours) time!
November 17, 2017 at 6:10 am #877943Hi,
I’m sorry if it’s getting a bit too long. Please note that this is not an issue with the theme. You’re asking for a custom modification which is actually beyond the scope of support. Please hire a freelance developer or contact our partner, Codeable.
Or post the FTP details in the private field so that we can test it.
Best regards,
IsmaelNovember 17, 2017 at 9:27 am #877982Hi Ismael, you are right. Give us a last try (please see FTP details in private content).
November 18, 2017 at 8:03 am #878388Hi,
Thank you for the info. I tried to create a test page with the Portfolio Grid or Masonry but the advance layout builder is not working because of the “mediaelementplayer” error brought by the WP 4.9 update. Please upgrade the theme to version 4.2.
Best regards,
IsmaelNovember 19, 2017 at 4:34 pm #878797… updated to enfod 4.2. – nothing changed – layout builder still not working!
On another installation layout builder work fine with:
– WordPress 4.9
– Enfold 4.1.1November 20, 2017 at 8:35 pm #879338– Layout builder problem is solved by your colleague Yigit.
– Order by ACF still not workingNovember 21, 2017 at 5:01 am #879471Hi,
I modified the filter in the functions.php file but it’s still not working. The “get_field” function is not working inside the query. The filter is working properly if the default post custom field is used. Please hire a freelance developer or contact our partner, Codeable to inspect the modification further.
UDPATE: Please ask the ACF author if we can access a custom field using another method aside from the get_field function.
Best regards,
IsmaelNovember 21, 2017 at 10:00 am #879587Hello Ismael,
thanks for your efforts. I will hire a freelancer ;-)November 22, 2017 at 5:27 am #880045 -
AuthorPosts
- You must be logged in to reply to this topic.