Question

The front page of my site building with set of widgets. Each widget shows the rows with posts for some criteria.

I want to exclude duplicate posts across different widgets. The simplest way comes to mind is to use global variable.

For example:

global $exclude;

$query = new WP_Query([
  'posts_per_page' => publish, 
  'post__not_in' => $exclude
]);

$exclude = wp_list_pluck( $query->posts, 'ID' );

I want to find better way to do this job. I've thought about wp_get_cache, but it seems that it is not what I want.

Était-ce utile?

La solution

Unfortunately no one answers my question so I will show my way to solve this problem.

I use public query vars with get_query_var and set_query_var functions to set widget__exclude variable across all queries.

Still not sure that it is the best way for this case but hope it helps somebody.

Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top