Tagged: acf, categories, sort
-
AuthorPosts
-
August 11, 2016 at 11:38 am #671248
Hey guys,
I’ve added an extra field to my blog posts “seminar_datum”. Now i want to sort my posts by this extra field. Is it possible?
I already enabled the custom order options, added the custom date: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', __('Seminar Datum', 'avia_framework' ) =>'seminar_datum') ); echo $elements; $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; }
But it didn’t work :( Do you guys know, how to address the field in the functions.php, so i can add this to the sorting order?
Thanks!
Henning- This topic was modified 8 years, 3 months ago by muschko.
August 13, 2016 at 9:08 am #672236Hey muschko,
What element are you using to show the Posts?
Best regards,
JosueAugust 15, 2016 at 8:34 am #672558Hey Josue,
i’m using the “Blog-Beiträge”-Element.
regards,
Hening- This reply was modified 8 years, 3 months ago by muschko.
August 16, 2016 at 3:20 am #672941Hi,
Can you please create us a WordPress administrator account? post it here as a private reply.
Regards,
JosueAugust 17, 2016 at 4:14 pm #673780Hey Josue,
thanks for your comment,
i can’t give you an admin account, because the customer don’t want to open his infos before launch.Do you have any other clues for me? Like an example or something else?
Thank your very much for your help,
HenningAugust 18, 2016 at 7:38 am #674067Hi,
Sure, basically you need to apply this to /enfold/config-templatebuilder/avia-shortcodes/postslider.php (575):
$query = array( 'orderby' => 'date', 'order' => 'DESC', 'paged' => $page, 'post_type' => $params['post_type'], 'posts_per_page' => $params['items'], 'offset' => $params['offset'], 'post__not_in' => (!empty($no_duplicates)) ? $avia_config['posts_on_current_page'] : array(), 'tax_query' => array( array( 'taxonomy' => $params['taxonomy'], 'field' => 'id', 'terms' => $terms, 'operator' => 'IN')));
Best regards,
Josue- This reply was modified 8 years, 3 months ago by Josue.
August 18, 2016 at 5:23 pm #674262ok thanks!
i applied this:
$query = array( ‘meta_key’ => ‘seminar_datum’,
‘orderby’ => ‘seminar_datum’,
‘order’ => ‘DESC’,
‘paged’ => $page,
‘post_type’ => $params[‘post_type’],
‘posts_per_page’ => $params[‘items’],
‘offset’ => $params[‘offset’],
‘post__not_in’ => (!empty($no_duplicates)) ? $avia_config[‘posts_on_current_page’] : array(),
‘tax_query’ => array( array( ‘taxonomy’ => $params[‘taxonomy’],
‘field’ => ‘id’,
‘terms’ => $terms,
‘operator’ => ‘IN’)));but i didn’t work… :-/ ( my date format is: yyyy-mm-dd
Second thing is… i just want this to apply, if the category is “seminare”.
like
$params[‘taxonomy’] == “seminare”
Thank you really much!
Henning- This reply was modified 8 years, 3 months ago by muschko.
August 19, 2016 at 3:25 am #674444Hi,
Can you post a screenshot or a link to the site? i’d like to see what kind of Blog are you using (as each one uses a different file), i’ll try to replicate your enviroment on my install so i can provide you the precise code.
Best regards,
JosueSeptember 26, 2016 at 1:07 am #691413This should work. (A modified version of Kriesi add orderby code http://kriesi.at/documentation/enfold/how-to-add-an-orderorderby-option-to-the-blogpost-sliderportfoliomasonry-grid-element/) Perhaps Kriesi can update their code, and or add a note about this to that post.
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(!empty($avia_config['avia_custom_query_options']['meta_key'])) { $query['meta_key'] = $avia_config['avia_custom_query_options']['meta_key']; } 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', __('Meta Value Number', 'avia_framework' ) =>'meta_value_num')); ); $elements[] = array( "name" => __("Custom Query Meta Key",'avia_framework' ), "desc" => __("Set custom meta keys to order by",'avia_framework' ), "id" => "meta_key", "type" => "select", "std" => "", "subtype" => array( __('None', 'avia_framework' ) =>'', __('Page 1 Order', 'avia_framework' ) =>'your_meta_key_1', __('Page 2 Order', 'avia_framework' ) =>'your_meta_key_2', __('Page 3 Order', 'avia_framework' ) =>'your_meta_key_3')); $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']; } if(!empty($atts['meta_key'])) { $avia_config['avia_custom_query_options']['meta_key'] = $atts['meta_key']; } return $meta; } }
Please note the addition of meta_key code in EACH function.
In the first $element[ ] notice the addition of__('Meta Value', 'avia_framework' ) =>'meta_value', __('Meta Value Number', 'avia_framework' ) =>'meta_value_num'));
In the second $elements[] code block, change
__('Page 1 Order', 'avia_framework' ) =>'your_meta_key_1',
To your specific page name, and your specific meta_key. In your case, it would look like htis:
__('Seminar Datum', 'avia_framework' ) =>'seminar_datum')
You can have as many meta_keys as you want.
Hope this helps!
elaine- This reply was modified 8 years, 1 month ago by iHuman.
September 26, 2016 at 7:33 am #691494October 25, 2018 at 4:20 am #1026186hello, what if i need to sort blog posts using two categories, ‘blog posts’ and ‘my featured blog posts’ ??
October 28, 2018 at 7:37 pm #1027303Hi,
You need to modify the query to include that, so basicly it has to be an array that will be the categories.
What are the slug names or the IDs’?Best regards,
BasilisOctober 31, 2018 at 1:44 am #1028323hi Basilis
i want to have a list of blogs where featured blogs show up first.
i have this situation:
blog posts category (primary)
ID = 114
slug = blog-postsfeatured blog posts category
ID = 9093
slug = featuredthe ‘featured’ category is a sub-category of ‘blog posts’, which is the primary category.
i am using Enfold 4.0.7
thank you
- This reply was modified 6 years ago by mm256. Reason: adding version of theme
November 5, 2018 at 4:36 am #1029743 -
AuthorPosts
- You must be logged in to reply to this topic.