Skip Navigation

[Resolved] Field not available under "Ordering"

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 18 replies, has 2 voices.

Last updated by Shane 5 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#1296349

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Susan,

So the issue is that the date is being stored incorrectly as a full string.

Is there a way for you to modify your code so that it is stored correctly as a timestamp?

I'm assuming this is what sets the date value to the database correct?

    'value'       => $form->get_campaign_value( 'startdate' ),

Please let me know as we need to convert this to a timestamp.

Thanks,
Shane

#1297781

Hi Shane,

After a bit of research and working with the plugin author there is no easy solution to get the dates to show up as dates versus text. His solution is that a WP_Query can be used to display the posts to order by meta value, where the meta value is interpreted as a date.

$query = new WP_Query( array(
'post_type' => 'campaign',
'meta_key' => '_campaign_startdate',
'orderby' => 'meta_value_date',
'order' => 'ASC',
) );

My issue comes in as to how to integrate this into the Toolset view so I can properly display the data.

#1298081

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Susan,

You can actually use a hook to do this.


add_filter( 'wpv_filter_query', 'date_filter_func', 10, 3 );
 
function date_filter_func( $query, $settings, $view_id ) {
    if ( $view_id == 1416 ) {
      $query = new WP_Query( array(
'post_type' => 'campaign',
'meta_key' => '_campaign_startdate',
'orderby' => 'meta_value_date',
'order' => 'ASC',
) );
    }
    return $query;
}

Change the id of the view and it should work.

Thanks,
Shane

#1298567

Hi Shane,

This still does not work. If I put the id of the view (5971), the page where the view's content template is suppose to show does not even render. If I put the id of the content template (5972) the page renders but the content is still not sorted correctly.

Any other ideas or can you go in and see what might be wrong ? This seems like such a simple thing that is just causing such an issue.

Thanks.

#1298861

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Susan,

So the issue we are facing here is that your date field is stored as a plain text string.

Now from what i've been reading it won't be possible to sort the date as it is.

It would need to be stored as a timestamp in order for us to sort it correctly.

Thanks,
Shane