Grow your CSS skills. Land your dream job.

php problem on WordPress ~ Please help!

  • # March 24, 2011 at 3:41 pm

    I added a field called date (a date time stamp)….The movies should then be queried based on the date. If the date is less than or equal to today, the movies will show on the now playing page. If the date is greater, then they will show on the coming soon page. I need to simply get the query string to work correctly

    < ?php query_posts ('cat=-12&meta_key=date&meta_value>=’.time());?>

    The problem I have is that it pulls in numerous copies of all of the posts.

    # March 24, 2011 at 4:03 pm

    I’m almost positive that you can’t use comparison operators in the query_posts function, such as “>=”.

    If that’s so, this will require a custom query… maybe something like this?


    < ?php
    wpdb->get_results(" SELECT * FROM $wpdb->posts WHERE post_date > '2011-03-24 00:00:00' ");
    ?>

    Some useful info if you’re not familiar with querying the database this way: http://codex.wordpress.org/Function_Reference/wpdb_Class

    # March 24, 2011 at 4:14 pm

    No, I’m not used to doing custom queries…..I don’t know where to start to do this even after looking over the codex

    # March 24, 2011 at 4:53 pm

    how can I reference time() in the custom query

    # March 24, 2011 at 4:54 pm

    I have tried the code below, but I don’t get results…

    # March 24, 2011 at 4:54 pm
    < ?php
    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wpostmeta.meta_key = 'date'
    AND wpostmeta.meta_value < = time()
    ";
    $pageposts = $wpdb->get_results($querystr, OBJECT);
    ?>
    # March 24, 2011 at 11:25 pm

    I found a super simple solution ~

    < ?php query_posts('cat=-12&post_status=future'); ?>

    Sure wish I would have found it sooner!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".