Home Forums Newsletter Plugin Support Need easy way to sort post lists by meta key

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #124212
    GalileeCentre
    Participant

    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?

    #124368
    prostasia
    Participant

    I 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?

    #124661
    Stefano
    Keymaster

    Hi, 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.

    #125374
    GalileeCentre
    Participant

    Firstly, 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.

    #125379
    GalileeCentre
    Participant

    To 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 list

    I 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: asc

    #125394
    prostasia
    Participant

    Oh, 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.

    #126355
    Anonymous
    Inactive

    hi

    #136357
    GalileeCentre
    Participant

    IF 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?

    #275457
    Paul Howe
    Participant

    I too would find this very useful. Would like to sort the Woocommerce product list included in an email by SKU.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.