• Resolved jameya17

    (@jameya17)


    Hi,

    I want to filter posts by custom date field in wp-query.

    for e.g. When year 2014 is selected i want to show all the post which have custom date value with year 2014.

    How to implement it in types plugin as types stores date value in timestamp.

    Thanks,
    Ameya

    https://www.ads-software.com/plugins/types/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Dear jameya17

    You must just create a timestamps for two date:

    2013-12-31 23:59:59
    2015-01-01 00:00:00

    And filter using meta_query

    $start = strtotime('2013-12-31 23:59:59');"
    $end = strtotime('2015-01-01 00:00:00');"

    And field value must be between this two timestamps.

    $date > $start && $date < $end

    Marcin

    Thread Starter jameya17

    (@jameya17)

    Hi,

    Thanks Marcin.

    It works perfectly.

    Thanks,
    Ameya

    pawciak

    (@pawciak)

    Hey Guys,

    Sorry for refreshing the subject. But I think it is somehow related to my issue. What I’ve wanted to achieve with wp-types was a kind of event addon. So simply I’ve added custom field with date and ok – posts appear with that. No issues. But a friend of mine (website owner) asked me to develop one more thing – calendar. Simple as it is – months with days and arrows to navigate.

    But I have no clue how to connect it with wp-types. Have anybody in the past tried to achieve something simillar?

    THanks!

    Dear Pawciak

    Few month ago I crated a plugin witch can display events in calendar, but … this is a very complicated think and probably very hard to do with Types.

    Look at https://core.svn.www.ads-software.com/tags/4.0.1/wp-includes/general-template.php function get_calendar.

    What You can do? Copy this function and manually add custom field to used SQLs.

    Cheers

    Marcin

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Filter Custom Posts by date field in wp-query’ is closed to new replies.