Tagged: , ,

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #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.
    #672236

    Hey muschko,

    What element are you using to show the Posts?

    Best regards,
    Josue

    #672558

    Hey Josue,

    i’m using the “Blog-Beiträge”-Element.

    regards,
    Hening

    • This reply was modified 8 years, 3 months ago by muschko.
    #672941

    Hi,

    Can you please create us a WordPress administrator account? post it here as a private reply.

    Regards,
    Josue

    #673780

    Hey 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,
    Henning

    #674067

    Hi,

    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.
    #674262

    ok 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.
    #674444

    Hi,

    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,
    Josue

    #691413

    This 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.
    #691494

    Hi,


    @iHuman
    thank you for sharing the code.


    @muschko
    please let us know if the above solution worked for you.

    Best regards,
    Vinay

    #1026186

    hello, what if i need to sort blog posts using two categories, ‘blog posts’ and ‘my featured blog posts’ ??

    #1027303

    Hi,

    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,
    Basilis

    #1028323

    hi 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-posts

    featured blog posts category
    ID = 9093
    slug = featured

    the ‘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
    #1029743

    Hi,

    You may need to add separate blog posts element and select one category for each element. Unfortunately, altering the query based on the conditions that you want is a bit complicated.

    Best regards,
    Ismael

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.