Group Admins

WordPress Troubleshooting and Support

Public Group active 1 year, 2 months ago ago

WordPress support from our community

wp_query with custom fields

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1486
    Jay
    Participant

    I want to create a wp_query to list the post titles of posts from category X, in ascending order based on a custom field I inputted in each post called “eventdate”.

    I tried the following code but it didnt work.

    http://pastebin.com/JmCMaB8B

    any idea how to fix? please advise. thanks in advance!

    #2573
    Steve
    Keymaster

    @Jake– Try this version: http://pastebin.com/XwvD9gBx

    #2574
    Jay
    Participant

    thanks but that doesnt seem to be working. nothing appears.

    to be clear, all posts in category X have a custom field name of “eventdate” then a number in the value field. the intention is to sort any posts with an “eventdate” custom field by the number in the corresponding value field.

    should the category_name be the category slug or actual name? i tried both.

    and am i supposed to replace CUSTOM-FIELD-NAME with something? you already put ‘eventdate’ as the post type so I guess that wouldnt be replacing CUSTOM-FIELD-NAME

    please advise. thank you.

    #2575
    Steve
    Keymaster

    @Jake– CUSTOM-FIELD-NAME should be replaced by your custom field you want to sort by. You wrote: “in ascending order based on a custom field “

    #2576
    Jay
    Participant

    i got it to work with this: http://pastebin.com/HEsQkJdw

    In the WP_Query, ‘post_type’ refers to a custom post type but i was trying to fetch posts by a category instead.

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