Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1229757

    Dear Enfold people,

    I want to order posts within one of my categories by alphabet. It concerns this page https://prideandsports.lapalma.org/lhbtiq-verenigingen/.
    I found your earlier reaction tot this question (#736541) and you said to use this code.
    ———–
    add_filter(‘avia_blog_post_query’, ‘avia_modify_post_grid_query_desc’);

    function avia_modify_post_grid_query_desc( $query ) {
    if( is_category( ‘blue-cheese’ ) ) {
    $query[‘orderby’] = ‘title’;
    $query[‘order’] = ‘DESC’;
    return $query;
    }
    }
    ———–

    My questions:
    1. Is this still the correct code to use?
    2. Where exactly should I put this code to make it work in my website?

    Kind regards from Amsterdam.
    Janneke Tichelaar

    #1230577

    Hey tichie,

    Thank you for the inquiry.

    Yes, the code above should still work — it will sort the posts based on their title. You could add it in the child theme’s functions.php file, but if there is no child theme yet, try to use this plugin.

    // https://wordpress.org/plugins/insert-headers-and-footers/

    Best regards,
    Ismael

    #1230862

    Hi Ismael,

    I restored the website on it’s final place so it is now on http://www.prideandsports.nl.

    I need the sort order of the category ‘noord-holland’ to change to alphabetical on this page https://prideandsports.nl/lhbtiq-verenigingen/. Both in the main content and in the right sidebar.

    I copied the code below into the functions.php file of the enfold-child theme, but I doesn’t seem to work.

    Regards,
    Janneke
    —————-

    add_filter(‘avia_blog_post_query’, ‘avia_modify_post_grid_query_desc’);
    function avia_modify_post_grid_query_desc( $query ) {
    if( is_category( ‘noord-holland’ ) ) {
    $query[‘orderby’] = ‘title’;
    $query[‘order’] = ‘DESC’;
    return $query;
    }
    }

    #1230866

    there is the code-snippet on the documentation: Link that may help you – to decide on the alb itself.

    put the snippet to your child-theme functions.php:
    ( on my point of view it is enough by the function itself to overwrite a plugable function on parent-theme )

    // this will insert on the given allowed elements some new Options for sorting 
    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;
    }
    // end of new options on sorting 

    Under the filters – you will have then :

    #1230894

    Hi,

    Thank you for the update.

    The is_category function will only work or will only return true if the current page is a category archive page. Maybe you need to use the is_page function instead.

    is_page:

    is_category:
    // https://developer.wordpress.org/reference/functions/is_category/

    Best regards,
    Ismael

    #1232764

    This is extremely useful, thank you very much

    #1232962

    Hi Antonia,

    Glad we could help :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

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