Support » Plugin: WordPress Infinite Scroll - Ajax Load More » Trouble combining a sort with a filter on custom field

  • Resolved deejmer

    (@deejmer)


    I have a hard-coded wp_query to have a ‘featured customer story’ on my website. It filters for the top (1) post, and that is set to ‘1’ on a boolean Advanced Custom Field called featured_content.

    I have an ajax_load_more listing all customer stories – but I do not want to include the featured post described above.

    I found examples of omitting results based on meta_key, but when I tried different things based on examples and forum posts I’ve found I could never get it to work.

    
    [ajax_load_more id="2347893455" container_type="div" post_type="customer_story" posts_per_page="6" orderby="meta_value" meta_key="customer_story_type" order="DESC"]
    

    I need to keep the orderby=”meta_value” meta_key=”customer_story_type” order=”DESC” part because I need a certain type of post to be listed before another, but need to add to this query to eliminate that featured post.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author dcooney

    (@dcooney)

    Hi @deejmer

    Are you have two issues?

    1. You are trying to exclude a post from the Ajax Load More listing?
    To do this you can pass the Post ID of the first post into the shortcode.
    Here is an example – https://connekthq.com/plugins/ajax-load-more/docs/code-samples/exclude-posts/

    2. You want to order results by multiple values?
    Let me know about this one.

    Hope this helps.

    I need to achieve two requirements in a single query.

    Yes, I want to exclude a post but it cannot be by ID. I want it to be dynamic. The query should exclude posts with meta_key:featured_customer where meta_value=1 {AND} ALSO ensure it has orderby set by meta_key:customer_story_type = DESC

    Hopefully that helps…

    Plugin Author dcooney

    (@dcooney)

    #1 – This is tricky. How would you do this in a regular WP Query?

    I think you might be best to run a custom query before ALM as shown in the exclude example above.
    Then pass the post IDs to the post__not_in parameter.

    #2 – after #1 is complete.
    add meta_key="" orderby="meta_value" to your shortcode.

    FYI – If you want to write your own query you can using the following filter.
    https://connekthq.com/plugins/ajax-load-more/docs/filter-hooks/#alm_query_args

    Hope that helps.

    deejmer

    (@deejmer)

    Thanks, that helped. I was able to get it working, thanks!

    • This reply was modified 2 months ago by  deejmer.
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.