Location rules determine which posts, pages, or contexts a field group appears on. Rules use an OR/AND structure.
Rule Format
php
// Show on posts OR pages
$rules = [
[ [ 'param' => 'post_type', 'operator' => '==', 'value' => 'post' ] ],
[ [ 'param' => 'post_type', 'operator' => '==', 'value' => 'page' ] ],
];
// Show on pages with a specific template AND top-level only
$rules = [
[
[ 'param' => 'post_type', 'operator' => '==', 'value' => 'page' ],
[ 'param' => 'post_template', 'operator' => '==', 'value' => 'templates/landing.php' ],
[ 'param' => 'page_type', 'operator' => '==', 'value' => 'top_level' ],
],
];Supported Parameters
| Param | Operators | Values |
|---|---|---|
post_type | ==, != | Any post type slug |
post_template | ==, != | Template filename or 'default' |
post_status | ==, != | publish, draft, etc. |
post_format | ==, != | standard, video, etc. |
post_category | ==, != | Category term ID |
post_taxonomy | ==, != | taxonomy:term_id format |
page | ==, != | Post ID as string |
page_type | ==, != | front_page, posts_page, top_level, parent, child |
page_parent | ==, != | Parent post ID |
current_user | ==, != | User ID |
current_user_role | ==, != | Role slug |
options_page | ==, != | Options page slug |
Custom Location Rule Parameters
php
add_filter( 'fieldforge/match_location_rule', function( $actual, $rule, $post ) {
if ( $rule['param'] === 'has_thumbnail' ) {
return has_post_thumbnail( $post->ID ) ? 'yes' : 'no';
}
return $actual;
}, 10, 3 );
// Usage: [ 'param' => 'has_thumbnail', 'operator' => '==', 'value' => 'yes' ]—