Skip to main content
Format code
Source Link
Jacob Peattie
  • 43.9k
  • 10
  • 49
  • 62

I am capturing a usersuser's Work Anniversary and their content is being stored in an array. So the key as it relates to these Meta Fields is 'hire_date'hire_date and the value that is stored in that array looks something like this 'a:2:{s:3:"day";s:1:"8";s:5:"month";s:5:"March";}'a:2:{s:3:"day";s:1:"8";s:5:"month";s:5:"March";}

What I don't really understand is how or what the 'orderby' => 'meta_value''orderby' => 'meta_value', is actually sorting by as the key has multiple values.

rightRight now if have the following code and I would like to know that the ASC order relates to the $current_day but I don't believe it is. I have tried using the 'type' => 'NUMERIC''type' => 'NUMERIC' and the 'orderby' => 'meta_value_num''orderby' => 'meta_value_num' but frankly I'm just not sure how to deal with this issue to display these work anniversary in ascending order in the month. Thanks

Thanks for any help solving this issue!

enter$current_month code= heredate('F');

$current_month = date('F'); $current_day = date('d'); $args_anniversary_current = array( 'role__in' => array('subscriber', 'subscriberlimited'), 'order' => 'ASC', 'orderby' => 'meta_value',

'meta_query' => array(

$current_day = date('d');
$args_anniversary_current = array(
'role__in' => array('subscriber', 'subscriberlimited'),
'order' => 'ASC',
'orderby' => 'meta_value',
    
'meta_query' => array(
    
        array(
            'relation'  => 'AND',

            array(
                'key'       => 'hire_date',
                'value'     => $current_month,
                'compare'   => 'LIKE',
            ),
            array(
                'key'       => 'hire_date',
                'value'     => $current_day,
                'compare'   => '>=',
            ),
        ),
    ),
);

);

I am capturing a users Work Anniversary and their content is being stored in an array. So the key as it relates to these Meta Fields is 'hire_date' and the value that is stored in that array looks something like this 'a:2:{s:3:"day";s:1:"8";s:5:"month";s:5:"March";}'

What I don't really understand is how or what the 'orderby' => 'meta_value', is actually sorting by as the key has multiple values.

right now if have the following code and I would like to know that the ASC order relates to the $current_day but I don't believe it is. I have tried using the 'type' => 'NUMERIC' and the 'orderby' => 'meta_value_num' but frankly I'm just not sure how to deal with this issue to display these work anniversary in ascending order in the month. Thanks for any help solving this issue!

enter code here

$current_month = date('F'); $current_day = date('d'); $args_anniversary_current = array( 'role__in' => array('subscriber', 'subscriberlimited'), 'order' => 'ASC', 'orderby' => 'meta_value',

'meta_query' => array(

    array(
        'relation'  => 'AND',

        array(
            'key'       => 'hire_date',
            'value'     => $current_month,
            'compare'   => 'LIKE',
        ),
        array(
            'key'       => 'hire_date',
            'value'     => $current_day,
            'compare'   => '>=',
        ),
    ),
),

);

I am capturing a user's Work Anniversary and their content is being stored in an array. So the key as it relates to these Meta Fields is hire_date and the value that is stored in that array looks something like this a:2:{s:3:"day";s:1:"8";s:5:"month";s:5:"March";}

What I don't really understand is how or what the 'orderby' => 'meta_value', is actually sorting by as the key has multiple values.

Right now if have the following code and I would like to know that the ASC order relates to the $current_day but I don't believe it is. I have tried using the 'type' => 'NUMERIC' and the 'orderby' => 'meta_value_num' but frankly I'm just not sure how to deal with this issue to display these work anniversary in ascending order in the month.

Thanks for any help solving this issue!

$current_month = date('F');
$current_day = date('d');
$args_anniversary_current = array(
'role__in' => array('subscriber', 'subscriberlimited'),
'order' => 'ASC',
'orderby' => 'meta_value',
    
'meta_query' => array(
    
        array(
            'relation'  => 'AND',

            array(
                'key'       => 'hire_date',
                'value'     => $current_month,
                'compare'   => 'LIKE',
            ),
            array(
                'key'       => 'hire_date',
                'value'     => $current_day,
                'compare'   => '>=',
            ),
        ),
    ),
);
Source Link

Reading Content in an Array as it relates to a meta_query

I am capturing a users Work Anniversary and their content is being stored in an array. So the key as it relates to these Meta Fields is 'hire_date' and the value that is stored in that array looks something like this 'a:2:{s:3:"day";s:1:"8";s:5:"month";s:5:"March";}'

What I don't really understand is how or what the 'orderby' => 'meta_value', is actually sorting by as the key has multiple values.

right now if have the following code and I would like to know that the ASC order relates to the $current_day but I don't believe it is. I have tried using the 'type' => 'NUMERIC' and the 'orderby' => 'meta_value_num' but frankly I'm just not sure how to deal with this issue to display these work anniversary in ascending order in the month. Thanks for any help solving this issue!

enter code here

$current_month = date('F'); $current_day = date('d'); $args_anniversary_current = array( 'role__in' => array('subscriber', 'subscriberlimited'), 'order' => 'ASC', 'orderby' => 'meta_value',

'meta_query' => array(

    array(
        'relation'  => 'AND',

        array(
            'key'       => 'hire_date',
            'value'     => $current_month,
            'compare'   => 'LIKE',
        ),
        array(
            'key'       => 'hire_date',
            'value'     => $current_day,
            'compare'   => '>=',
        ),
    ),
),

);