Sort Order in Block

Posted in: Newspaper
Post count: 59

Hi guys,

At the moment I can sort posts by -Latest- in Block Edit (Visual Composer) Is it possible to reverse order to have the newest posts at the back of the row? Means not latest on first position but oldest?

That would be a great help. Cheers.

The more I dig into your theme the more I’m amazed what you have produced with this theme. I think it’s the best wp theme on the net!!

Post count: 3343

Hi,
1. Add this code: 'Older' => 'older', http://screencast.com/t/H05LvbnKSc1H
2. Add this code:

case 'older':
$wp_query_args['orderby'] = 'date';
$wp_query_args['order'] = 'ASC';
break;

like here: http://screencast.com/t/rZsVKY8pJC

3. http://screencast.com/t/qar81j8WEJM9

Thanks!

Post count: 3343

Hi, I thing the correct word is Oldest 🙂 Sorry for my spelling

Post count: 59

Hi Marius,

works like a charm. Thanks very much.

My problem now: I’m pulling custom post types from Events Manager plugin into your block.

The sorting works obviously via the creation date. Is it possible to edit the

$wp_query_args[‘orderby’] = ‘date’;

to order by the events manager date (the date the event actually happens (which is in the future mostly, so wouldn’t be displayed with your query)

Here the events manager columns:
post_type = “events”
Post: “EM_Event_Post”
Date: “the_date”

Cheers

Post count: 3343

Hi,
Create a new sorting option for block like: 'Upcoming events' => 'upcoming'
http://screencast.com/t/KSZwIHciLGBb

Add this code:

case 'upcoming':
                $wp_query_args['orderby'] = 'event_start_date';
                $wp_query_args['order'] = 'ASC';
                break;

http://screencast.com/t/r3NgmTl6hev

Now you can order by upcoming date http://screencast.com/t/xSB8Cyei

Here are all attributes that you can use for other sorting type: http://wp-events-plugin.com/documentation/event-search-attributes/

Thanks!

Post count: 59

Hey Marius,

Thanks for the quick reply.

Sadly, this sorting query doesn’t work. It’s being ignored. It still sorts via post creation date – not actual event date. Hmmmh…

Any idea?

Cheers

Post count: 3343

Hi,
I’ve tested locally when I’ve implemented the code for you and work fine for me.
Please can you double check if you make all the steps correctly.

Also for the date can be modified to read the event date instead of the post date, but i’m not sure.

Thanks for your message!

Post count: 59

Hi Marius,

what do you mean by that: “Also for the date can be modified to read the event date instead of the post date, but i’m not sure.”?

Did you sort on your local machine by post date or by event date? I double checked. The sorting with your code goes via post date.

Would you mind double check your settings on your local machine?

Thanks for your time.

Post count: 3343

Hi,
I mean you can display the date of the event instead of the post date like here: http://screencast.com/t/itXPBdFPV

To do that replace code like here: http://screencast.com/t/TM3Sx1AKK

            if ( 'event' == get_post_type($this->post->ID) ) {
                $EM_Event = em_get_event($this->post->ID, 'post_id');

                $buffy .= '<time  itemprop="dateCreated" class="entry-date updated' . $visibility_class . '" datetime="' . date(DATE_W3C, $td_article_date_unix) . '" >' . $EM_Event->output('#_EVENTDATES') . '</time>';
                $buffy .= '<meta itemprop="interactionCount" content="UserComments:' . get_comments_number($this->post->ID) . '"/>';
            } else {
                $buffy .= '<time  itemprop="dateCreated" class="entry-date updated' . $visibility_class . '" datetime="' . date(DATE_W3C, $td_article_date_unix) . '" >' . get_the_time(get_option('date_format'), $this->post->ID) . '</time>';
                $buffy .= '<meta itemprop="interactionCount" content="UserComments:' . get_comments_number($this->post->ID) . '"/>';
            }

And yes, the code above should work

see here all the screenshot:
http://screencast.com/t/2STtSmDmr
http://screencast.com/t/nEDmVsGBh

Result:

no sorting: http://screencast.com/t/oV07D1ERa
sorting by date(upcoming event): http://screencast.com/t/itXPBdFPV

Thanks!

Post count: 59

Hi Marius,

your are right, it sorts the asc und desc order of the events. The Problem is that it sorts via post date. let me explain:

It works when you post events in chronological order. But when you insert an event inbetween two already existing events (for example you have an event on the 1st of April and on the 4th of April and then later post an event on the 2nd of April it will be put at the back of the list and not between the existing dates). It’s running into problems.

Please change your post dates in Events Manager (the date the event was created). And you’ll see what I mean.

Any ideas?

Post count: 3343

Hi,
Yes, i found it,
this is the correct code:

            case 'upcoming':
                $wp_query_args['meta_key'] = '_event_start_date';
                $wp_query_args['orderby'] = 'meta_value';
                $wp_query_args['order'] = 'ASC';
                $wp_query_args['meta_query'] = array(
                    array(
                        'key' => '_start_ts',
                        'value' => current_time('timestamp'),
                        'compare' => '>=',
                        'type'=>'numeric'
                    )
                );
                break;

http://screencast.com/t/hcJ3Bw7EcR

Now sort by start event date and remove the expired event. If you want to show expired event to remove this from code: http://screencast.com/t/j3aaAsKDwWm

Thanks! 🙂

Post count: 20

Marius, I am using the simple plugin Post Expirator [https://wordpress.org/plugins/post-expirator]

How could I use this script to sort by post expiring showing First?

I added the line

'Event Expiring' => 'event',

To the td_generic_filter_array.php file

Post count: 3343

Hi,
In td_generic_filter_array.php you define a new sorting option, then for that option you have to add that code in td_data_source.php for your case http://screencast.com/t/gZqc7Mfe

Hope this help!

Post count: 20

Thanks! Was able to get it working with the following code.

      case 'event':
                $wp_query_args['meta_key'] = '_expiration-date';
                $wp_query_args['orderby'] = 'meta_value';
                $wp_query_args['order'] = 'ASC';
                break;
Post count: 3343

Hi,
Great! I’m glad that you have managed.

Post count: 59

Thanks Marius, works like a charm !!

Post count: 11

Hi,

Can you update this to work with the current version of Newspaper. It’s exactly what I’m looking for to sort my events properly.

Ben

Post count: 22421

Hello Ben,

As you can see this is a very old topic. Since then we have added new sorting options in the blocks. Please check the block settings and sorting options available: https://forum.tagdiv.com/block-settings-guide/

Thank you!

Viewing 18 posts - 1 through 18 (of 18 total)
The forum ‘Newspaper’ is closed to new topics and replies.