Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Martin Stehle

    (@hinjiriyo)

    That is an interesting question and there is an answer. Add the following code at the end of the file ‘functions.php’ of the active theme:

    function rpwwt_get_posts_of_current_month ( $query_args ) {
    	$today = getdate();
    	$query_args[ 'date_query' ] = array(
    		array(
    			'month' => $today['mon'],
    		),
    	);
    	return $query_args;
    }
    add_filter( 'rpwwt_widget_posts_args', 'rpwwt_get_posts_of_current_month' );
    Thread Starter stavroch

    (@stavroch)

    Thank you Martin!

    So when I have to display the posts of current month do I have to add any shortcode or just publish the widget to the area that I want?

    Plugin Author Martin Stehle

    (@hinjiriyo)

    You just publish the widget where you want to display it. You can add and remove the code whenever you want to filter oder not to filter to the posts of the current month.

    Plugin Author Martin Stehle

    (@hinjiriyo)

    I have to correct my former code because the parameter of the current year is missing. Otherwise all posts published in the same month name of the current month in the past would be listed. The revised ocde is:

    function rpwwt_get_posts_of_current_month ( $query_args ) {
    	$today = getdate();
    	$query_args[ 'date_query' ] = array(
    		array(
    			'year' => $today['year'],
    			'month' => $today['mon'],
    		),
    	);
    	return $query_args;
    }
    add_filter( 'rpwwt_widget_posts_args', 'rpwwt_get_posts_of_current_month' );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display posts of current month’ is closed to new replies.