Sorting events in Wordpress Bedrock template

87 views Asked by At

Wordpress site build on Bedrock needs template adjustment. Events displayed in the template are sorted from the oldest to the newest. I assume this is default behavior, as I can't see any specific part responsible for sorting.

I would like to sort events from the newest to the oldest.

Code in the template for displaying events:

  <list-posts
      :list="{{ $past_events }}"
      api-url="/wp-json/version/past-events"
    >
      <template v-slot:default="{ list }">
        <event-card
          v-for="event in list"
          :key="event.id"
          :event="event"
          type="overview"
        >

I tried to add different sorting command to the end of "wp-json..." path:

?filter[orderby]=date&order=desc
?filter[orderby]=event_date&order=desc
?orderby=date&order=desc

but they break the site (each line used separately).

I would appreciate any hint on how to correctly sort events (newest to oldest).

1

There are 1 answers

0
James Webb On

Create a computed property and sort the array there.

https://v2.vuejs.org/v2/guide/computed.html

<div id="example">
  <p>Original message: "{{ message }}"</p>
  <p>Computed reversed message: "{{ reversedMessage }}"</p>
</div>
var component = new Vue({
  el: '#example',
  data: {
    message: 'Hello'
  },
  computed: {
    // a computed getter
    reversedMessage: function () {
      return this.message.split('').reverse().join('')
    }
  }
})

You might be able to sort this only once and store in the data object if you wanted to try and be more efficient.