WP Manifestindependent plugin directory
manifest / performance / internal-flags

Internal Flags

Use a hidden taxonomy to improve expensive queries.

★ 5stars
453kcomposer installs
v0.2.0latest · 4 years ago

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/alleyinteractive/internal-flags/archive/refs/heads/develop.zip

On Packagist as alleyinteractive/internal-flags:

composer require alleyinteractive/internal-flags
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

Creates a hidden taxonomy to improve expensive query performance by not relying on meta queries. Allows for 'flags' to be set/unset on posts easily and entirely hidden from the end-user.

Instructions

By default, the internal taxonomy will be added to all registered post types.

Common Use Cases

  • Hiding from archives/searches
  • Posts by an author (where author is stored as a meta normally)
  • Showing/hiding sponsored posts

Usage

Setting a flag on a post

use Internal_Flags\set_flag;
set_flag( 'hide-from-archives', $post_id );

Removing a flag on a post

use Internal_Flags\remove_flag;
remove_flag( 'hide-from-archives', $post_id );

Checking if a flag is on a post

use Internal_Flags\has_flag;
has_flag( 'hide-from-archives', $post_id ); // bool

Searching for posts with a flag

use Internal_Flags\get_flag_tax_query;
$posts = new \WP_Query(
    [
        // ...
        'tax_query' => [
            get_flag_tax_query( 'show-on-page' )
        ],
    ],
);

Searching for posts without a flag

Inverse of the above

use Internal_Flags\get_flag_tax_query;
$posts = new \WP_Query(
    [
        // ...
        'tax_query' => [
            get_flag_tax_query( 'hide-from-archives', false )
        ],
    ],
);

Releases

1 release.

Tag
Published
v0.2.0 latest
Jul 27, 2022 4 years ago

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.