Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter tramacriacoes

    (@tramacriacoes)

    My solution:

    add_shortcode('recent_posts_week', 'shortcode_recent_posts_week');
    function shortcode_recent_posts_week() {
    
    $the_query = new WP_Query( 'cat=noticias-semana' ); 
    
    	if ( $the_query->have_posts() ) : 
    
    		$html = '<div class="container">';
    
    		while ( $the_query->have_posts() ) : $the_query->the_post(); 
    
    			if($sinaval_post_year != get_the_date( 'Y' )) {
    				$html .= '<h2><a href="'.site_url().'/'.get_the_date( 'Y' ).'">'.get_the_date( 'Y' ).'</a></h2>';
    			};
    			if($sinaval_post_week != get_the_date( 'W' )) {
    				$html .= '<h3>From '.date('j/M/Y',strtotime(get_the_date( 'Y' ).'W'.get_the_date( 'W' )));
    				$html .= ' til '.date('j/M/Y',strtotime('this friday '.get_the_date( 'Y-n-j' ))).'</h3>';
    			};
    			$sinaval_post_year = get_the_date( 'Y' );
    			$sinaval_post_week = get_the_date( 'W' );
    
    			$sinaval_post_format = get_post_format(get_the_ID());
    			if($sinaval_post_format == "link") {
    				$html .= '<h4><a href="'.get_the_content().'" target="_blank">'.get_the_title().'</a> </h4>';
    			} else {
    				$html .= '<h4><a href="'.get_permalink(get_the_ID()).'">'.get_the_title().'</a></h4>';
    			};
    			$html .= '<ul class="meta">';
    			$html .= '<li><span class="date">'.get_the_time('j/n/Y').'</span></li>';
    			$html .= '</ul>';
    
    		endwhile;
    
    	$html .= '</div>';
    
    	wp_reset_postdata();
    
    	return $html;
    
    	endif;
    }

    Turns out I didn’t need the date_query at all, just some php’ strtotime and wordpress’ get_the_date.

    Since Alex, said it was not easy, I think I’m missing something here, but the code is working well (still needs some testing).

    But thanks for the quick response!

Viewing 1 replies (of 1 total)