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

Usage does not work: "->where( 'post_level', '=', 2 )" and "->where( 'post_parent_id', '=', 12 )" #1197

Open
valexxas opened this issue Nov 7, 2023 · 2 comments

Comments

@valexxas
Copy link

valexxas commented Nov 7, 2023

Version

  • Carbon Fields: 3.6.3
  • WordPress: 6.3.2 / 6.4
  • PHP: 8.1.9

Expected Behavior

Output meta fields only on child pages for the specified specific page

Actual Behavior

The nesting level and parent page are not defined.
If the condition is ->where( 'post_parent_id', '=', 0 ), then the fields will be displayed on all pages, including on child pages (having a parent page).
Also, when using ->where( 'post_level', '=', 0 ), the field is always output, including on child pages.
When specifying ->where( 'post_level', '=', <ANY_NUMBER>) or ->where( 'post_parent_id', '=', <ID_PARENT_PAGE> ) the fields are not output anywhere.

Container definition

add_action( 'carbon_fields_register_fields', function () {
	Container::make( 'post_meta', __( 'Meta fields' ) )
		//->where( 'post_type', '=', 'page' )
		//->where( 'post_level', '=', 2  )
		->where( 'post_parent_id', '=', 15 )
        ->add_fields( array(
		Field::make( 'text', 'page_title', 'Page Title' )
            ,
		) )
	;
} );

Comments

I'm sorry, I'm using a translator to communicate with you. There may be problems with the translation of phrases.

@valexxas
Copy link
Author

valexxas commented Nov 7, 2023

I will supplement it.
Conditions: child page, condition for fields "->where( 'post_level', '=', 1 )" ( only the first level, not child ones), fields should not be output.
What happens: the CarbonFields fields are output, the input values are not saved. On the pages of the first level, the fields are displayed, their values are saved.
Removing the condition "->where( 'post_level', '=', 1 )". Result: fields are displayed everywhere, all values are saved as they should be.

@valexxas
Copy link
Author

valexxas commented Apr 9, 2024

After experimentation, the problem was circumvented by a similar condition:

Container::make( 'post_meta',__( 'Meta fields' ) )
  ->where( 'post_type', '=', 'page' )
  ->where( 'post_level', 'CUSTOM', function( $post_level ) {
  return ( $post_level == 2 );
   } )
// OR
  ->where( 'post_parent_id', 'CUSTOM', function( $post_parent_id ) {
	return ( $post_parent_id == wc_get_page_id( 'shop' ) );
  } )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant