K
K
Karl Meinhoff2016-08-20 10:12:17
CMS
Karl Meinhoff, 2016-08-20 10:12:17

How to filter articles on the front page in WordPress?

There was a task - to display on the main page of an article only with a certain label. How to do it?
Please do not send to Google, very urgent.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2016-08-20
@KarleKremen

Do you know how to write your own WP_Query? Add 'tag' => 'tag slug' to the arguments.
Or if you have a regular WP cycle on the main page, you can add code like

add_action('pre_get_posts','my_tag_query');

function my_tag_query($query){
    if( $query->is_front_page() && $query->is_main_query() && ! $query->is_admin()) {
        $query->set('tag', 'слаг метки');
    }
};

This is if by tags, of course, you mean built-in tags in WP

N
Nikita, 2016-08-20
@Nivalis

I did through arbitrary fields, and then in the code I made a selection using the field values, but it is quite possible that there is an easier way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question