Support

Account

Forum Replies Created

  • Does this work as well without the fields IDs (like field_56faad2a333ab) but with field names?

  • Thanks. Years after I had time to go back to this project.
    WP_Query did the trick:

    	
            date_default_timezone_set("Europe/Zurich");
    	$dateNow = date('Y-m-d H:i:s');
    
            $args = array(
    		'post_type' => 'veranstaltungen',
    		'post_status' => 'publish',
    		'order' => 'DESC',
    		'orderby' => 'meta_value',
    		'meta_query' => array(
    			array(
    				'key'           => 'event_date',
    				'compare'       => '>=',
    				'value'         => $dateNow,
    				'type'          => 'DATETIME',
    			),
    		),
    		'numberposts' => -1,
    	);
    
    	$query = new WP_Query($args);
    
    	$posts = $query->posts;
    
  • Anything, anyone? I really need this to get working, but I haven’t found any solution…

  • Unforunately the filtering still does not work:
    I have now:

    
    $startDate = date('Y-m-d H:i:s', strtotime('-2 days'));
    
    $posts = get_posts([
    		'post_type' => 'veranstaltungen',
    		'post_status' => 'publish',
    		'order' => 'DESC',
    		'orderby' => 'meta_value'.
    		'meta_query', array( array( 'key' => 'event_date', 'value' => $startDate, 'compare' => '>=')),
    		'numberposts' => -1,
    	]);
    

    But I would still get all my events displayed. Also clearly the ones that have an event_date smaller than the $startDate

    What would I have to add to get i to work?
    Is it really possible to compare

    2019-11-20 19:30:00 >= 2019-12-02 10:43:05

    I feel like that is not gonna work…

  • Yeah sorry, it is clearly a date/time field.

  • @hube2
    thanks for your input.
    I tried this as well, but unfortunately it does not have any effect either.

    When I print out the event_date I get a value like 2019-12-04 19:30:00.
    I think with your code I am comparing my $startDate which is something like 20191201 to 2019-12-04 19:30:00.

    I assume to use a compare operator of > I need to have actual numbers.
    So using the $startDate works but we would have to compare it against 20191204 instead 2019-12-04 19:30:00.

    Could that be the issue?
    And how would I transform the event_date within get_posts

    Thanks for your input.Cheers

  • @iosman123
    Could you maybe share your code. I still had no success in achieving a proper filter. I just keep getting all posts at a time…

  • Thank you for your input.

    Well I tried your first idea, and it did not work.
    It is just exactly the same.
    It is as if the filter is just not applied at all.
    Honestly I would have wondered if adding an order would have resolved it.

    I then tried your second suggestion, because I indeed don’t need another meta field.
    But this also does not work. Exactly the same as above.

    Playing with the syntax is difficult if I don’t see any effect at all…

    Am i missing something with the syntax? Is there something with Date fields that is different from other filter comparisons? Is there any way to gain more insight what my filter actually does? Like logging an actual comparison, to see which dates are compared and what the outcome of it is?

    Thanks in advance.
    Cheers

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