Skip to:
Content
Pages
Categories
Search
Top
Bottom

Count replies ant get last activity link


  • rederis
    Participant

    @rederis

    Hi, I am trying to grab all replies and count them (7 days old only)
    Then I want to put on my nav menu message “There is new posts in formum ( 4hours 21mins ago )
    1. Problem post_type Reply doesn’t work
    2. Can’t access bbp functions in main-theme
    3. It counts and renews only new TOPICS

    function count_new_forum_posts() {
    
    $today = date("Y-m-d");
    
    $date2 = date("Y-m-d", strtotime($today . "-7 Day")); 	
    $args = array(
    		'post_type' => 'topic',
    		'meta_query' => array(
    			array(
    				'key' => '_bbp_last_active_time',
    				'value' => $date2,
    				'type' => 'DATE',
    				'compare' => '>='
    					),
    				)
    );
    
    $posts_query = new WP_Query($args);
    $the_count = $posts_query->post_count;
    
    return $the_count;
    
    }
    add_filter('wp_nav_menu_items', 'new_forums_notice_to_menu', 10, 2);
     
     function new_forums_notice_to_menu($items, $args) {
    	 if(count_new_forum_posts() > 0){
              if( $args->theme_location == 'primary' )
              $items .= '<li><a href="http://apygarda/forums/" text-transform="lowercase" text-shadow="2px 1px 2px black"><font color="red">Šios savaitės naujos žinutės forume: <span>'.count_new_forum_posts().' ('.bbp_forum_freshness_link().')</span></font></a></li>';
         return $items;
     }else{
    	           if( $args->theme_location == 'primary' )
              $items .= '<li><a href="http://apygarda/forums/" text-transform="lowercase" text-shadow="2px 1px 2px black"><font color="gray">Šią savaitę forume dar niekas nepasisakė</span></font></a></li>';
         return $items;
     }
    }
Viewing 5 replies - 1 through 5 (of 5 total)

  • Robin W
    Moderator

    @robin-w

    last active time on a topic would pick up if there had been replies.

    I loaded your code onto my site, and it worked fine.

    I’m not sure what other help you want

    1. topic will do what you want, it is saying that there are new topics within the period
    2. I don’t understand this question, works fine on my test site]
    3. yes it is counting any new topics or topics where there have been new replies – is that nit what you want?


    rederis
    Participant

    @rederis

    If I have this week 2 old topics with 2 and 3 replies within this week. I need to print out
    “There is 5 replies this week (last one 5 mins ago)”.
    Currently it prints
    “There is 2 topics this week ()”.

    When I change post_type from Topic to Reply
    “There is 0 replies this week ()”


    Robin W
    Moderator

    @robin-w

    ok, that may well be beyond free help, but what is doing that print out – nothing in your code send any of that to screen


    rederis
    Participant

    @rederis

    function new_forums_notice_to_menu($items, $args) {
    	 if(count_new_forum_posts() > 0){
              if( $args->theme_location == 'primary' )
              $items .= '<li><a href="http://***/forums/" text-transform="lowercase" text-shadow="2px 1px 2px black"><font color="red">Šios savaitės naujos žinutės forume: <span>'.count_new_forum_posts().' ('.count_new_forum_post_time().')</span></font></a></li>';
         return $items;

    I try to hook up to my menu (later on exact menu element “Forums” ) to print “There is (count_new_forum_posts()) new posts this week”

    My head menu should be Home Personel Phones Forum (2) News. But now there is problem only with replies count. I think there is problem with my query ‘key’ => ‘_bbp_last_active_time’ cant be assosiated with ‘replies’ data only with ‘Topics’. I am very green on programming so strugling. I already fixed kinda problem by adding (last reply date – current date time diference).


    Robin W
    Moderator

    @robin-w

    ok, both topics and replies are custom post types, so the date of both is in the posts table, so no meta query needed.

    so

    ‘post_type’ => array( ‘topic’, ‘reply ) if you want both

    and look at

    WP_Query

    scroll down to date parameters to work out how to do the date

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar