Regarding Wordpress article display

Asked 1 years ago, Updated 1 years ago, 64 views

I'm a beginner at Wordpress.

There is a page that shows all the articles in a category, and it creates a page that contains links for each archive and links for each child category in that category.
If you click on the child category link, they won't go to read the category. The article in the archive will be read.
I would like to display articles for each child category, but is the code below?

I would appreciate it if someone could tell me.

<?php
$args = array(
    'post_type' = > 'works',
    'post_status' = > 'public',
    'posts_per_page' = > 24,
    'paged'=>(get_query_var('page'))?absint(get_query_var('page')): 1,
    'tax_query' = > array(
        array(
            'taxonomy' = > 'works_cat',
            'field' = > 'slug',
            'terms' = > 'photo'
        )
    )
);
foreach($_GET as$k=>$v){
    if(preg_match('/year(2[0-9][0-9][0-9])/',$k,$matches)===1){
        $args['year'] = $matches[1];
        break;
    }
}
$works_query=newWP_Query($args);
?>

php wordpress

2022-09-30 14:08

1 Answers

Use 'date_query' to narrow down the date of publication, etc.
For more information, see the https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/WP_Query Date Parameters.
The following are examples to be narrowed down in 2017

$args=array(
    'post_type' = > 'works',
   'date_query' = > array(
        array(
            'year' = > '2017'
        )
    )
);


2022-09-30 14:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.