black friday sale

Custom Fields
Re-Envisioned
Support MB Relationships Use setting field value in field query_args

  • Creator
    Topic
  • #21699
    Resolved 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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #21705
    Long 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ó
    Participant

    Using get_option() works, thank you!

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