Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the term context to allow adding a field to any child terms only #875

Open
renatonascalves opened this issue Aug 29, 2024 · 2 comments
Labels
enhancement New feature or request php Requires understanding PHP scope:context scope:field

Comments

@renatonascalves
Copy link

Description

Ideally, Fieldmanager_Context_Term could be extended so that a field using this context can be added to child terms only (or maybe only to parent terms too).

Currently, one can set a specific parent term id:

/**
* Only show this field on child terms of this parent.
*
* @var int
*/
public $parent = '';

Use Case

Here is a real use case where this was needed and could be used:

$fm = new Fieldmanager_Checkbox(
	[
		'checked_value' => '1',
		'name'          => 'field_key',
	]
);

$fm->add_term_meta_box(
	title: __( 'Enable in Child Term Only' ),
	taxonomies: [ 'category', 'post_tag' ],
	show_on_add: false,
	parent: 254546546 // This only works if one sets the parent term ID.
);
@renatonascalves renatonascalves added enhancement New feature or request scope:context scope:field php Requires understanding PHP labels Aug 29, 2024
@mboynes
Copy link
Contributor

mboynes commented Aug 29, 2024

Do you think that this is a necessary change for FM to make, or is it something that could easily be accomplished outside of FM? For instance...

$term = get_queried_object();
if ( $term instanceof \WP_Term && $term->parent ) {
    // FM definitions...
}

@renatonascalves
Copy link
Author

renatonascalves commented Aug 29, 2024

Do you think that this is a necessary change for FM to make

I thought about suggesting this into the core plugin because it already offers a similar option with the parent. But it is not required to be.

Meaning that my suggestion was less about making it work for the use case and more about suggesting it is baked in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request php Requires understanding PHP scope:context scope:field
Projects
None yet
Development

No branches or pull requests

2 participants