Home › Forums › Newsletter Plugin Support › Need easy way to sort post lists by meta key
- This topic has 8 replies, 5 voices, and was last updated 3 years, 2 months ago by Paul Howe.
-
AuthorPosts
-
October 5, 2018 at 5:00 pm #124212GalileeCentreParticipant
Hi there, We use a meta key to sort posts by date on our site. (We post events on our wordpress as individual posts, and select the date that the event is happening, which is stored in a meta key)
We send out monthly updates using your plugin, adding a post list to the bottom of the message.
Up until now after every update, I have added some code to various functions within your plugin to force it to sort the post list by our meta key.
As there may not always be a skilled IT person here, I need to ensure this sorting will continue into the future and will persist over updates.
Do you have a better way to do this? Possibly an add-on or hidden setting that I have overlooked?October 7, 2018 at 12:21 am #124368prostasiaParticipantI too need a feature like this, except in my case rather than sorting the newsletters, it would be filtering them out if they match a certain metadata field.
If we could pay the authors of this plugin to make this for us (either as an upgrade to the next release or as a paid plugin), would you go halves with me on the cost?
October 8, 2018 at 2:02 pm #124661StefanoKeymasterHi, you need to code a custom theme. We have not room right now for custom coding, but a theme is nothing else than a loop between posts, like in a WP theme, so a code should be able to start from our default theme and change the filter.
Stefano.
October 11, 2018 at 8:21 pm #125374GalileeCentreParticipantFirstly, to Protasia:
I am not sorting newsletters, but rather a lists of posts that is embedded within them by the newsletter plugin. If you are referring to a list of posts on your site itself, perhaps on a page, that is quite easy and I can help you with that.secondly, to Stefano (or any of the NewsLetter Plugin staff)
Your plugin uses it’s own query via get_posts() to pull the list of posts for use. Can I simply override your function by using an action/filter of my own? Where in your code is this and what is it’s function name?I have a custom code plugin that I use to add all of my custom code to. In it, I have modified the main query via pre_get_posts to properly sort any and all posts that are not pages (and have the meta key).
Unless your plugin changes the information being passed to and from get_posts() in a significant way, it should be a relatively simple matter to add a filter to catch calls to your custom query function and pass them through my own instead, thus keeping the category and post number filters, but adding the sort data, then returning the results.
Please get back to me as soon as you can.
October 11, 2018 at 8:38 pm #125379GalileeCentreParticipantTo clarify my question:
right now the code seems to do something like this:
ADD POST LIST TO EMAIL
1) -> add a title, set font size and whether you want the images, set query data(select categories, select number of posts
2) -> send query data to get_posts or pre_get_posts
3) -> get_posts or pre_get_posts receives query
—post type
—category
—number of posts to get
4) -> function returns post data, sorted by date posted in either ascending or descending order
5) -> post data is run through a loop and formatted post-by-post, and added to the listI want to intercept the get_posts or pre_get_posts call that your plugin makes so that my sorting requirements get added to the query.
Unless I misunderstand how your plugin is doing things, I should be able to pass the whole query from the ADD POST LIST TO EMAIL dialog through the function, which should add the following items to the query before it gets passed to get_posts:
– order by: meta_value
– meta_key: <our custom meta key>
– order: ascOctober 11, 2018 at 10:01 pm #125394prostasiaParticipantOh, sorry for my misunderstanding GalileeCentre, I now understand how our problems are different. Your offer of advice is much appreciated though. jeremy at prostasia.org will get to me.
October 17, 2018 at 6:40 am #126355AnonymousInactivehi
November 29, 2018 at 7:26 pm #136357GalileeCentreParticipantIF we were to use a custom theme, how would one go about using the drag and drop creator within it? or is this not possible?
September 19, 2021 at 10:47 pm #275457Paul HoweParticipantI too would find this very useful. Would like to sort the Woocommerce product list included in an email by SKU.
-
AuthorPosts
- You must be logged in to reply to this topic.