Use setting field value in field query_args

Support MB Relationships Use setting field value in field query_argsResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #21699
    Imre LászlóImre László
    Participant

    Hello!

    I've created a custom relationship between WooCoomerce products and pages:

        add_action('mb_relationships_init', function() {
          MB_Relationships_API::register(array(
            'id' => 'gg_products_to_page',
            'from' => 'product',
            'to' => array(
              'post_type' => 'page',
              'field' => array(
                'query_args' => array(
                  'post_parent' => (int) rwmb_meta('gg-packages-parent-page', array('object_type' => 'setting'), 'ggbox_settings')
                ),
                'clone' => false
              )
            ),
            'reciprocal' => true
          ));
        });

    The problem: rwmb_meta in this hook always returns false. 🙁 How can I properly adjust the code to use a predefined setting variable in relationship settings? If I call the rwmb_meta() function elsewhere, it works and returns the currect setting value.

    Thanks!

    #21705
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Because the relationship action runs before the settings page so it does not get the value from the helper function. You can use the function get_option() to get a field value from the settings page.

    'query_args' => array(
      'post_parent' => (int) get_option( 'ggbox_settings' )['gg-packages-parent-page']
    ),
    #21706
    Imre LászlóImre László
    Participant

    Using get_option() works, thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.