B
B
Boris Belov2016-02-12 18:34:00
WordPress
Boris Belov, 2016-02-12 18:34:00

How to correctly display posts for the current Monday from a specific category?

Hello.
It is necessary to display posts for the current Monday from a certain category (for example = 4 )

<?php 
    $params = array(

      'date_query' => array(array('dayofweek' => 2)),);
$week = date('W');
$year = date('Y');

$the_query = new WP_Query( $params, 'year=' . $year . '&w=' . $week); ?>
    <?php while  ($the_query->have_posts() ) : $the_query->the_post(); ?>

---
The code worked fine if so ( $params ); and then only displayed for Monday, but in general for all weeks. or if so ( 'year=' . $year . '&w=' . $week) , but then only for that week.
You need to connect $params + 'year=' somehow. $year. '&w=' . $week + cat=4
Help with a solution!
-----
It turned out to display only posts for this week, from category 4. It remains to register the parameter for displaying posts for Monday. $the_query = new WP_Query( $params . "&cat=4&year=$year&w=$week" ); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Belov, 2016-02-12
@iborisbelov

The question is closed.

<?php 
    
$week = date('W');
$year = date('Y');
$params = array(
'date_query' => array(array('dayofweek' => 2)),
'cat'=> '4',
'year'=> $year,
'w'=> $week,
);
$the_query = new WP_Query($params ); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question