Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
106 views
in Technique[技术] by (71.8m points)

javascript - Sorting events in Wordpress Bedrock template

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).

question from:https://stackoverflow.com/questions/65866128/sorting-events-in-wordpress-bedrock-template

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Create a computed property and sort the array there.

https://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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...