Problem to filter on date
-
Hi.
I am french , I’ve create a script who count how many tweet / like exists on posts related to one post.
For exemple , I have a single post which is Microsoft , a simple slide about the company and I have some other type of post called “news”.
I Count the like / tweet for each news and I create a global count on the post Microsoft.This part of the script works very well, but when I want to had a filter on the date of publication, it’s doesn’t work. That I try; is to select only the “news” I have write since 30 days but my function return only the post I have write since 30 days.
Here is my script, and you can see the result on this URL : http://www.frenchstartups.com/script-total.php
Do you have an idea how to make this work ?
Thanks a lot ,
Regards , Florian#!/usr/local/bin/php
<?phprequire_once( dirname(__FILE__) . ‘/wp-load.php’ );
$args = array(
‘post_type’ => ‘post’,
‘post_status’ => ‘publish’ );
$myposts = new WP_Query( $args );while ($myposts->have_posts()) : $myposts->the_post();
echo(“
“);the_title();$args2=array(
‘connected_type’ => ‘news_to_posts’,
‘connected_items’ => $post,
‘connected_direction’ => ‘from’,
‘connected_meta_query’ => array(
‘relation’ => ‘AND’,
array(
‘key’ => ‘post_date’,
‘value’ => date(“Y-m-d H:i:s”, strtotime(‘-30 days’)),
‘compare’ => ‘>’,
‘type’ => ‘DATETIME’
)
),
‘connected_orderby’ => ‘meta_value_num’,
‘connected_order’ => ‘DSC’);$connected = new WP_Query($args2);
// var_dump($connected);$post_id = get_the_ID();
if ( $connected->have_posts() ) :
$total = 0;
while ( $connected->have_posts() ) : $connected->the_post();
echo(“
“);the_title();
echo(“
“);the_date();
$posttest = array(‘tweets’=> get_field(‘nbre_tweet’), ‘like’=> get_field(‘nbre_like’), ‘googleplus’=> get_field(‘nbre_plus’), ‘linkedin’=> get_field(‘nbre_linkedin’));
$soustotal = array_sum($posttest);
$total += $soustotal;
var_dump($total);
endwhile;
$field_key = “field_50b10d608183c”;
$value = $total;
update_field( $field_key, $value, $post_id);
wp_reset_postdata();
endif;
wp_reset_query();
endwhile;?>
The topic ‘Problem to filter on date’ is closed to new replies.