T
T
Theory Theory2020-12-09 09:38:36
SQL
Theory Theory, 2020-12-09 09:38:36

How to make a request depending on the current language?

Site on wp, multilingual. Polylang plugin
such sql query returns all posts in both English and Russian.

SELECT * FROM $wpdb->posts WHERE post_type = 'post'


How to return posts only in Russian or only in English?

More or less like this:
SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND locale=ru
???

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
yarovikov, 2020-12-09
@Narbek

A language in polylang is a custom taxonomy. Look in a DB as it stores the data.
An example of an array when using a class for database queries:

$args = array(
  'category'  => pll_get_term(34)
);

A
Artem Zolin, 2020-12-09
@artzolin

You can get the current localization with get_locale(). Returns the string en_US, ru_RU, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question