SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict
    Join Date
    Sep 2009
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Order by meta fields in Wordpress

    I may have made a poor decision but I have some custom fields in Wordpress that allow users to input numbers for a month, day and year. I wanted this separate from the publish date fields in WP because I felt this would be easier and because the client has lots of older content they need to publish.

    So how can I query and order by meta fields or what is the best way to do this? order by the day, month and year fields, all of which contain numbers.

    Thanks in advance.

  2. #2
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I would tell them to use the publish field, and type in the [old] dates by hand. If you have 5 posts and they were dated in the last week, withe the newest at #1. Publishing it with a date of Dec 23, 2011, will put it at #6 not #1.
    Ryan B | My Blog | Twitter

  3. #3
    SitePoint Addict
    Join Date
    Sep 2009
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rguy84 View Post
    I would tell them to use the publish field, and type in the [old] dates by hand. If you have 5 posts and they were dated in the last week, withe the newest at #1. Publishing it with a date of Dec 23, 2011, will put it at #6 not #1.
    So is that generally the best way to go about it? Part of the reason I set it up this way was because sometimes articles are published that have different dates from when the WP post is published so I created these fields to differentiate.

  4. #4
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You can make the WP publish date anything from either 1-1-1900 or 1970 to 12-31-9999, this is a MySQL limitation. @r937 would know the answer.

    Are you bringing the old content in to have it all there (like archiving) or do you want to push the content as new and just be able to say give me stuff originally written in 2005?
    Ryan B | My Blog | Twitter

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    sorry, no idea, i don't do wordpress
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Rudy, my throw to you was the date ranges in MySQL.
    Ryan B | My Blog | Twitter

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    date ranges depend on which datatype is being used to store the date, and as i said, i don't know wordpress, so i don't know which of the 4 different ways of storing dates applies here

    da manual is the best reference for datatypes

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #8
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Oh ok, I didn't realise that there were 4.
    Ryan B | My Blog | Twitter

  9. #9
    SitePoint Addict
    Join Date
    Sep 2009
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The datatype is a text field for month, day and year. I assumed there could be a way to read those as numbers and have some formula to be able to organize it appropriately.

  10. #10
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Rpeg, can you answer the question I asked in #4?
    Ryan B | My Blog | Twitter


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •