Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Order CPT in query loop by custom field

  • Hi David

    I’ve recorded myself double-chekcing this and the field name – just so I get clear in my own mind that I’ve set it up correctly.

    https://www.loom.com/share/4383904722db4859aafe390c1b7ed7a8?sid=c9991cc3-94dc-4275-b806-26da4a7c344e

    Maybe you’ll spot something I’ve done wrong? Otherwise I’m at a loss.

    Thanks
    Dom

  • What’s the return format of the ACF date custom field ?

  • Y-m-d H:i:s (YYYY-MM-DD HH:II:SS) according to the resources.

    https://www.advancedcustomfields.com/resources/date-time-picker/

  • Oh, I can edit this. This is what I have set: https://ibb.co/dcDSTB6

  • Hmmm… I can’t see what is wrong.
    That all looks correct to me.

    Check for plugin conflicts ?

  • OK, will try that next.

    What should I see with the var_dump hook? Should that output the date/time?

  • You have 2 query loops with the same CSS class order-priority on the same page, can you remove one of the query loop blocks to test?

  • Hi all

    I’ve deactivated all plugins save for GP Premium GB/GB Pro and ACF Pro

    I’ve added a new number field group called “Priority” and added this to the var_dump – it still displays “array(0) {}”

    I’ve then added a numeric priority to each of the events posts

    I’ve copied the code for numeric values directly from the tutorial

    Purged all cache

    It still doesn’t sort them into an order.

    Next, I tried adding the Priority custom field to a standard post categorised as “Test Category” and created a completely new query loop displaying this category. Grid has CSS class “order-by-number”, which I then changed in the functions.php

    https://staging-inspirewomenoldham-co-uk.stackstaging.com/test-category-sorting/

    It’s not sorting these either.

    I do very much appreciate your continued support on this, btw.

    Thanks
    Dom

  • Hi Dom,

    I see. Can you share admin login credentials to this Staging site through the Private Information field? We’ll try to do some tests.

  • Will do.

    Thanks
    Dom

  • The var_dump won’t work on the archive page.
    It would only work on the single post where the ACF field is located.

    But considering the ACF date appears in your loops template then we know its getting a value.
    Its whether its a) valid for the query or b) the filter hook is actually working as expected.

    I logged into your site, and temporarily activated the child theme. And the filter function in there worked on the archive page… so that function is working.

    So I took a peak at the child theme functions and noticed there was an ACF filter for adding @ support in the datetime fields. Was that active when testing the date field?

  • Ah, OK. Yes, the @ support has been there a while, although not throughout, I don’t think. I’ll try removing that.

  • OK, I’ve removed the @ support and added the var_dump hook to individual events. So now something is being outputted to the events, but the query loop is not sorting into order.

  • A breakthrough of sorts. I removed the @ support and tried again with the simple “Priority” number field – and that is now working on the test loop: https://staging-inspirewomenoldham-co-uk.stackstaging.com/test-category-sorting/

    I’ll come back to this on Monday and see if I can get the dates to do the same thing.

    Have a good weekend.

  • I couldn’t leave it alone. I got it working with a date field (no time) using the third example in the tutorial. This might be enough, unless they decide to run multiple events on the same day.

    I might have another go with the date and time next week.

    Again, can’t thank you enough for the help.

    Dom

  • Glad to hear that Dom, I tested the DATETIME type on my site and it worked as expected, so I assume it should work on your site as well 🙂

    Have a great weekend!

Viewing 16 posts - 17 through 32 (of 32 total)
  • You must be logged in to reply to this topic.