https://github.com/alleyinteractive/internal-flags
Use a hidden taxonomy to improve expensive queries.
https://github.com/alleyinteractive/internal-flags
wordpress wordpress-plugin
Last synced: 4 months ago
JSON representation
Use a hidden taxonomy to improve expensive queries.
- Host: GitHub
- URL: https://github.com/alleyinteractive/internal-flags
- Owner: alleyinteractive
- Created: 2020-03-31T02:57:09.000Z (about 6 years ago)
- Default Branch: develop
- Last Pushed: 2023-02-21T19:58:12.000Z (over 3 years ago)
- Last Synced: 2024-10-13T21:54:18.570Z (over 1 year ago)
- Topics: wordpress, wordpress-plugin
- Language: PHP
- Homepage:
- Size: 94.7 KB
- Stars: 5
- Watchers: 34
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Internal Flags
==============
[](https://github.com/alleyinteractive/internal-flags/actions/workflows/unit-test.yml)
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
```php
use Internal_Flags\set_flag;
set_flag( 'hide-from-archives', $post_id );
```
### Removing a flag on a post
```php
use Internal_Flags\remove_flag;
remove_flag( 'hide-from-archives', $post_id );
```
### Checking if a flag is on a post
```php
use Internal_Flags\has_flag;
has_flag( 'hide-from-archives', $post_id ); // bool
```
### Searching for posts with a flag
```php
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_
```php
use Internal_Flags\get_flag_tax_query;
$posts = new \WP_Query(
[
// ...
'tax_query' => [
get_flag_tax_query( 'hide-from-archives', false )
],
],
);
```