Contributors: dipesh.kakadiya Tags: term, primary Requires at least: 4.5 Requires PHP: 5.6 Tested up to: 5.3 Stable tag: 1.0 License: GPLv2
Allows you to choose primary term for posts and custom post types.
Allows you to choose primary taxonomy for posts and custom post types. This plugin only work with WordPress Classic Editor.
- Add the plugin's folder in the WordPress' plugin directory.
- Activate the plugin.
- Now you will have the ability to make any term a primary term for the post
if you want to filter post and custom post types based on their primary categories.
For primary term query, Meta key will be _primary_<taxonomy>
Ex For Category filter key will be _primary_category
/**
* This snippet fetch 10 published posts which have category ID 5
* marked as primary category
*/
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '10',
'meta_query' => array(
'relation' => 'AND',
'array(
'key' => '_primary_category',
'value' => '5',
'compare' => '='
),
),
);
$main_query = new WP_Query( $args );
/**
* This snippet fetch 10 published posts which have category ID 5 or 2
* marked as primary category
*/
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '10',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_primary_category',
'value' => '5,2',
'compare' => 'IN'
),
),
);
$main_query = new WP_Query( $args );
wppt_get_the_primary_term( $taxonomy, $id, $before, $after );
$taxonomy : Taxonomy name.
$id : Post ID or post object. Defaults to global $post [ Optional ] .
$before : Before link [ Optional ].
$after : After link [ Optional ].
wppt_get_primary_term( $taxonomy, $id );
$taxonomy : Taxonomy name.
$id : Post ID or post object. Defaults to global $post [ Optional ].
wppt_get_primary_term_id( $taxonomy, $id );
$taxonomy : Taxonomy name.
$id : Post ID or post object. Defaults to global $post [ Optional ].
wppt_get_primary_taxonomies();
- Initial Development.