-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadme.txt
101 lines (78 loc) · 2.43 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# WordPress Primary Term
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.
## Description
Allows you to choose primary taxonomy for posts and custom post types.
This plugin only work with WordPress Classic Editor.
## Installation
1. Add the plugin's folder in the WordPress' plugin directory.
2. Activate the plugin.
3. Now you will have the ability to make any term a primary term for the post
## Developers' Notes
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 );
```
## Template functions
### Get a post Primary term link
`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 ].
### Get a post Primary term object
`wppt_get_primary_term( $taxonomy, $id );`
$taxonomy : Taxonomy name.
$id : Post ID or post object. Defaults to global $post [ Optional ].
### Get a post Primary term Id
`wppt_get_primary_term_id( $taxonomy, $id );`
$taxonomy : Taxonomy name.
$id : Post ID or post object. Defaults to global $post [ Optional ].
### Get taxonomy array which are support primary term
`wppt_get_primary_taxonomies();`
## Changelog
### 1.0
* Initial Development.