Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter tjldesigns

    (@tjldesigns)

    This is basically what I’m trying to get work:

    [ajax_load_more post_type="people" meta_key="people_title_order:people_surname:people_key_contact" meta_value="0:crazytown:1" meta_compare=">:!=:!=" meta_type="NUMERIC:CHAR:NUMERIC" meta_relation="AND" orderby="meta_value_num meta_value" order="ASC" posts_per_page="6" pause="true" scroll="false" transition="fade" transition_speed="1000" button_label="View more" button_loading_label="Loading..." container_type="div" css_classes="people-grid people-grid-gap-top"]

    The people_key_contact will always be equal to 0 so the ordering of that won’t affect anything (I just need that there to make sure it only brings in entries not = 1, so will all be 0).

    The two fields I then want to order by are people_title_order ASC, then people_surname ASC, but it’s sadly not working.

    Many thanks,
    TJ

    Plugin Author Darren Cooney

    (@dcooney)

    Hi TJ,
    To be honest I’m not really sure how to do this using multiple custom field values.

    I would have thought meta_value_num/meta_value would have worked.

    A quick search turns out that you may need to customize the query a bit.
    https://www.google.ca/search?q=wordpress+order+by+multiple+custom+fields

    You could likely use the alm_modify_query_args(0 filter.
    https://connekthq.com/plugins/ajax-load-more/docs/filter-hooks/#alm_modify_query_args

    Let me know if this helps.

    Thread Starter tjldesigns

    (@tjldesigns)

    Hey Darren,

    Thanks so much for your quick reply ??

    Basically that is now working with orderby=”meta_value_num meta_value” order=”ASC”

    BUT meta_value_num is ordering ASC, and meta_value is ordering DESC.

    I tried changing order to :

    order=”ASC ASC” or order=”ASC:ASC”

    But sadly it then just reverted the whole ordering to DESC, as it mustn’t accept those values.

    Would there be any way via the shortcode to get this to work, as it’s so close :).

    Many thanks,
    TJ

    Thread Starter tjldesigns

    (@tjldesigns)

    Hey Darren,

    In the meantime just so I could try and get it working, I did as per your other suggestion :

    function my_custom_alm_modify_query_args( $args, $page ) {
       // $args = current ajax load more $args
       // $page = current page slug
       if($page === 'people'){
          $args['post_type'] = 'people';
          $args['nopaging'] = 'true';
          $args['meta_query'] = array(
            array(
                'key' => 'people_key_contact_order'
            ),
            array(
                'key' => 'people_surname'
            ),
            array(
                'key' => 'people_key_contact',
                'value' => '0',
                'compare' => '=='
            )
          );
          $args['orderby'] = array(
          		'meta_value_num' => 'ASC',
          		'meta_value' => 'ASC'
          );
    
       }
       return $args;
    }
    add_filter( 'alm_modify_query_args', 'my_custom_alm_modify_query_args', 10, 2);

    But sadly that’s not working… /people/ is an archive page and not an actual page slug, would that make a difference and should I do anything different to get this working?

    Either way though, still hoping we can get the shortcode version working as it seems almost there! If we can’t though, would it be an update you would consider for future, where you allow for multiple ordering fields, to also allow the “order” to be controlled for these too individually? So can be ASC, another DESC and so on ??

    Many thanks,
    TJ

    Plugin Author Darren Cooney

    (@dcooney)

    Hi TJ,

    But sadly that’s not working… /people/ is an archive page and not an actual page slug, would that make a difference and should I do anything different to get this working?

    Yea, that might be an issue with the filter args.

    Is it even possible to use the order param with multiple values?
    'order' => 'ASC, DESC',

    Thread Starter tjldesigns

    (@tjldesigns)

    Hey Darren,

    Thanks again for your reply :).

    Yes, I did wonder if the archive was the problem.

    And back to your question, yep you certainly can, basically the below works :

    $args_keycontacts = array(
                                'post_type' => 'people',
                                'nopaging ' => true,
                                'meta_query' => array(
                                    array(
                                        'key' => 'people_key_contact_order'
                                    ),
                                    array(
                                        'key' => 'people_surname'
                                    ),
                                    array(
                                        'key' => 'people_key_contact',
                                        'value' => '1',
                                        'compare' => '=='
                                    )
                                ),
                                'orderby'  => array( 'meta_value_num' => 'ASC', 'meta_value' => 'ASC' ),
                            );

    So, if we could get your shortcode to allow for that, that would be the perfect solution as it is almost there, it’s just the second param reverting to DESC which poses the issue.

    Many thanks,
    TJ

    Plugin Author Darren Cooney

    (@dcooney)

    Since it’s an archive and the if($page ===) doesn’t work.

    Is it possible to pass a value through the custom_args shortcode param to the filter and then verify.

    For example.
    The shortcode:
    [ajax_load_more custom_args="people_archive:true"]

    Then the filter:

    function my_custom_alm_modify_query_args( $args, $page ) {
       if($args['people_archive'] === 'true'){
    
          $args['orderby'] = array(
          	'meta_value_num' => 'ASC',
          	'meta_value' => 'ASC'
          );
    
       }
       return $args;
    }
    add_filter( 'alm_modify_query_args', 'my_custom_alm_modify_query_args', 10, 2);

    Just an idea.

    Thread Starter tjldesigns

    (@tjldesigns)

    Thanks Darren, sooo…. I tried this :

    function my_custom_alm_modify_query_args( $args, $page ) {
       if($args['people_archive'] === 'true'){
    
          $args['order'] = array(
          		'meta_value_num' => 'ASC',
          		'meta_value' => 'ASC'
          );
    
       }
       return $args;
    }
    add_filter( 'alm_modify_query_args', 'my_custom_alm_modify_query_args', 10, 2);

    But sadly it does what it does on the shortcode when I tried say… order=”ASC ASC” it’s just reverted it all to order DESC, so then totally ignores ASC…

    I did try exactly as per your example too with the

    $args['orderby'] = array(
          	'meta_value_num' => 'ASC',
          	'meta_value' => 'ASC'
          );

    But sadly that didn’t work either, hence my trying the above just in case that did it ??

    Plugin Author Darren Cooney

    (@dcooney)

    Well, I’m stumped.
    Sorry man.

    I assume you confirmed the modify filter was running?

    Thread Starter tjldesigns

    (@tjldesigns)

    Yep sure did as some other bits I tried actually clearly broke it as then no results showed.

    It makes no sense does it… and so frustrating as all that lets it down on the shortcode is the fact that the second meta_value is ordering DESC

    So I guess nothing more I can tinker with? I don’t want to tamper with any plugin code either as then it breaks it away from any updates you may make in future which is never very good.

    Thanks Darren

    Thread Starter tjldesigns

    (@tjldesigns)

    I’ve been studying this more as I have more data and I’ve realised that actually… meta_value_num is definitely ordering ASC as I mentioned.

    BUT where I thought the second order field, meta_value, was ordering DESC, it seems it actually isn’t. So it’s totally ignoring that field for ordering. Based on the logic of the plugin, just wondered do you know what secondary ordering that will be defaulting to?

    Also, I wonder, do you think this would ever be an update you would consider for your plugin, to allow for more multiple meta value ordering, as we know WP_Query can handle it? ??

    Plugin Author Darren Cooney

    (@dcooney)

    I don’t think I will update the plugin simply because the modify filter should be working. It’s there to override shortcode params.

    I’m wondering if because you are NOT explicitly overriding the ‘order’ param it is still being processed. The only param updating is ‘orderby’.

    If you want to mod the core ajax-load-more.php file please feel free. Then pass along your findings.

    Would that work?

    Thread Starter tjldesigns

    (@tjldesigns)

    Hey Darren,

    Finally had chance to play with this again… And so I changed the fields around, and managed to get it working another way, and by using the principles you suggested with the my_custom_alm_modify_query_args in functions and passing the custom_args for the archive hook.

    So thank you so much again for your help and patience with this, you definitely helped steer me in the right direction :).

    Many thanks,
    TJ

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Ordering by multiple fields’ is closed to new replies.