Tagged: 

Viewing 23 posts - 1 through 23 (of 23 total)
  • Author
    Posts
  • #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;
        }
    }
    #873155

    are 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 ago by Guenni007.
    #873336

    Hello 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?

    #873993

    Hi,

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

    #874084

    Good 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”?

    #874456

    Hi,

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

    #874563

    Good 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?

    #875019

    Hi,

    My bad. It’s an invalid code. Please replace it with:

    $query['meta_key'] = $value;
    

    Best regards,
    Ismael

    #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;
        }
    }
    
    #875930

    Hi,

    Could you provide an example of the “kursbeginn” custom field value?

    Best regards,
    Ismael

    #875997

    Hi 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)

    #876486

    Hi!

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

    #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?

    #877337

    Hi,

    The functions.php file is blank. I can’t see any code in it. Please check the screenshot.

    // https://imgur.com/a/S79GC

    Best regards,
    Ismael

    #877416

    OK, 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!

    #877943

    Hi,

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

    #877982

    Hi Ismael, you are right. Give us a last try (please see FTP details in private content).

    #878388

    Hi,

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

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

    #879338

    – Layout builder problem is solved by your colleague Yigit.
    – Order by ACF still not working

    #879471

    Hi,

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

    #879587

    Hello Ismael,
    thanks for your efforts. I will hire a freelancer ;-)

    #880045

    Hi,

    Alright. Please update us once the modification is implemented.

    Best regards,
    Ismael

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