I have a class that I am using as part of the CMB2 framework for WordPress. It has a protected object that I am trying to append a list of years to. My code looks like this in my function
function cmb2_team_members_metaboxes() {
global $redux_rg;
$prefix = '_cmb2_';
$cmb_team_members = new_cmb2_box(array(
'id' => 'team_member_metabox',
'title' => __( 'Team Member Metabox', 'rev-group' ),
'object_types' => array( 'post_type_teammember', ), // Post type
'context' => 'normal', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => true, // Show field names on the left
));
I add more fields then below I am trying to append the years() output to an options list of an HTML select / dropdown. to do this I need to append $cmb_team_members->meta_box['fields']['_cmb_start_year']['options'] with the output array from the function years(). Below is where I am trying to extend CMB2 class which is protected with the years() output.
class yearsClass extends CMB2
{
public function __set($name, $value)
{
$this->$cmb_team_members->meta_box['fields']['_cmb_start_year']['options'] = years();
}
}
I know I am doing this completely wrong but I can't seem to crack this. Any help would be appreciated.
I have years defined in my functions.php file and it outputs:
array(
2015 => 2015,
2014 => 2014
)
When I output the CMB2 Object I get this:
CMB2 Object (
[cmb_id:protected] => team_member_metabox
[meta_box:protected] => Array
(
[id] => team_member_metabox
[title] => Team Member Metabox
[type] =>
[object_types] => Array
(
[0] => post_type_teammember
)
[context] => normal
[priority] => high
[show_names] => 1
[show_on_cb] =>
[show_on] => Array
(
)
[cmb_styles] => 1
[enqueue_js] => 1
[fields] => Array
(
[_cmb2_division] => Array
(
[name] => Division
[desc] => The division of the company this person works in (These can be edited in the Revolution Group theme options)
[id] => _cmb2_division
[type] => select
[options] => Array
(
)
)
[_cmb2_photo] => Array
(
[name] => Photo
[desc] =>
[id] => _cmb2_photo
[type] => file
)
[_cmb2_position] => Array
(
[name] => Position
[desc] => Job position
[id] => _cmb2_position
[type] => text
)
[_cmb2_email] => Array
(
[name] => Email
[desc] => Email address
[id] => _cmb2_email
[type] => text_email
)
[_cmb2_bio] => Array
(
[name] => Bio
[desc] =>
[id] => _cmb2_bio
[type] => wysiwyg
[options] => Array
(
[media_buttons] => 1
[textarea_rows] => 5
)
)
[_cmb2_start_year] => Array
(
[name] => Year Started
[desc] => The year the team member started with Revolution Group
[id] => _cmb2_start_year
[type] => select
[options] => Array
(
)
)
[_cmb2_certifications_repeat_group] => Array
(
[id] => _cmb2_certifications_repeat_group
[type] => group
[description] => Certifications (These can be edited in the Revolution Group theme options)
[options] => Array
(
[group_title] => Certification {#}
[add_button] => Add Another Certification
[remove_button] => Remove Certification
[sortable] => 1
)
[fields] => Array
(
[certification] => Array
(
[name] => Certification
[description] => Please select
[id] => _cmb2_certification
[type] => select
[options] => Array
(
)
)
[certification_year] => Array
(
[name] => Year Obtained
[description] => The year this certification was aquired
[id] => _cmb2_certification_year
[type] => select
[options] => Array
(
)
)
)
)
[_cmb2_skills_repeat_group] => Array
(
[id] => _cmb2_skills_repeat_group
[type] => group
[description] => Skills (These can be edited in the Revolution Group theme options)
[options] => Array
(
[group_title] => Skill {#}
[add_button] => Add Another Skill
[remove_button] => Remove Skill
[sortable] => 1
)
[fields] => Array
(
[skill] => Array
(
[name] => Skill
[description] => Please select
[id] => _cmb2_skill
[type] => select
[options] => Array
(
)
)
)
)
[_cmb2_fun_fact] => Array
(
[name] => Fun Fact
[desc] =>
[id] => _cmb2_fun_fact
[type] => wysiwyg
[options] => Array
(
[media_buttons] => 1
[textarea_rows] => 5
)
)
[_cmb2_order] => Array
(
[name] => Order
[desc] => Order that the team member should be displayed. The lower the number the hghter on the list when displayed
[id] => _cmb2_order
[type] => text
)
)
[hookup] => 1
[save_fields] => 1
[closed] =>
[new_user_section] => add-new-user
)
[object_id:protected] => 0
[object_type:protected] => post
[mb_object_type:protected] => post
[updated:protected] => Array
(
)
[mb_defaults:protected] => Array
(
[id] =>
[title] =>
[type] =>
[object_types] => Array
(
)
[context] => normal
[priority] => high
[show_names] => 1
[show_on_cb] =>
[show_on] => Array
(
)
[cmb_styles] => 1
[enqueue_js] => 1
[fields] => Array
(
)
[hookup] => 1
[save_fields] => 1
[closed] =>
[new_user_section] => add-new-user
)
[fields:protected] => Array
(
)
[hidden_fields:protected] => Array
(
)
[data_to_save] => Array
(
)
[generated_nonce:protected] =>
)
Related
I am pulling a product list back with Rest API in PHP for Shopify:
$resp = $Rest->get(
'products',
[],
[
'limit' => 250,
'fields' => 'id,title,variants',
'published_status' => 'published',
'status' => 'active'
]
);
This results in the following response:
Array
(
[0] => stdClass Object
(
[id] => 237462354
[title] => Product 1 title
[variants] => Array
(
[0] => stdClass Object
(
[product_id] => 237462354
[id] => 1481824
[title] => Default Title
[price] => 105.99
[sku] => MYSKU11002
[position] => 1
[inventory_policy] => deny
[compare_at_price] =>
[fulfillment_service] => manual
[inventory_management] => shopify
[option1] => Default Title
[option2] =>
[option3] =>
[created_at] => 2022-08-12T10:13:39-04:00
[updated_at] => 2022-08-16T14:55:31-04:00
[taxable] => 1
[barcode] => 814812747124
[grams] => 2268
[image_id] =>
[weight] => 5
[weight_unit] => lb
[old_inventory_quantity] => 1
[requires_shipping] => 1
)
)
)
What I would prefer is the following response type:
Array
(
[0] => stdClass Object
(
[id] => 237462354
[title] => Product 1 title
[variants] => Array
(
[0] => stdClass Object
(
[product_id] => 237462354
[sku] => MYSKU11002
)
)
)
This basically requires modifying the fields so that we just get the product_id and sku for the variants returned per product.
I have tried using fields=id,title,variants.sku, fields=id,title,variants/sku, fields=id,title,variants[sku] with no luck.
Is this possible? You can do it in GraphQL - I know that much, so it would make sense if it were possible in the PHP Rest API also.
I'm trying to get the first deal ID from AgileCRM.
When using:
$test = json_decode($deal, true);
print_r($test);
I get the following result:
Array (
[0] => Array (
[colorName] => WHITE
[id] => 5686812383117312
[apply_discount] =>
[discount_value] => 0
[discount_amt] => 0
[discount_type] => Value
[name] => New Home Loan
[contact_ids] => Array (
[0] => 5645056174194688
)
[custom_data] => Array (
)
[products] => Array (
)
[description] => New Lead
[expected_value] => 0
[milestone] => New Loan
[probability] => 10
[close_date] => 1521192269
[created_time] => 1510824270
[milestone_changed_time] => 0
[entity_type] => deal
[notes] => Array (
)
[note_ids] => Array (
)
[note_created_time] => 0
[pipeline_id] => 5719238044024832
[archived] =>
[lost_reason_id] => 0
[deal_source_id] => 0
[total_deal_value] => 0
[updated_time] => 1510824270
[isCurrencyUpdateRequired] => 1
[currency_conversion_value] => 0
[tags] => Array (
)
[tagsWithTime] => Array (
)
[contacts] => Array (
[0] => Array (
[id] => 5645056174194688
[type] => PERSON
[properties] => Array (
[0] => Array (
[type] => SYSTEM
[name] => first_name
[value] => piet
)
[1] => Array (
[type] => SYSTEM
[name] => last_name
[value] => pompies
)
[2] => Array (
[type] => SYSTEM
[name] => name
[value] =>
)
)
)
)
[owner] => Array (
[id] => 5178546118721536
[domain] => domainname
[email] => myemail#email.com
[phone] =>
[name] => Piet Pompies
[pic] => https://d1gwclp1pmzk26.cloudfront.net/img/gravatar/48.png
[schedule_id] => Piet Pompies
[calendar_url] => https://homeside.agilecrm.com/calendar/Piet_Pompies
[calendarURL] => https://homeside.agilecrm.com/calendar/Piet_Pompies
)
)
)
I want to echo "5686812383117312" from "[id] => 5686812383117312" (4th line in the array above)
I've tried "foreach" statements but my expertise on it is limited and can't seem to get it right.
Any help will be appreciated.
In order to access the ID field you should:
get the array's first key
Access the required field
Array:
Array ( //$test
[0] => Array ( //first key [0]
[colorName] => WHITE
[id] => 5686812383117312 //the required field ['id']
[apply_discount] =>
PHP:
$test = json_decode($deal, true);
print_r($test);
echo $test[0]['id']; //Output: 5686812383117312
Jcart Object(
[config] => Array
(
[jcartPath] => jcart/
[checkoutPath] => checkout.php
[item] => Array
(
[id] => my-item-id
[name] => my-item-name
[price] => my-item-price
[qty] => my-item-qty
[url] => my-item-url
[add] => my-add-button
)
[paypal] => Array
(
[id] => seller_1282188508_biz#conceptlogic.com
[https] => 1
[sandbox] =>
[returnUrl] =>
[notifyUrl] =>
)
[currencyCode] => USD
[csrfToken] =>
[text] => Array
(
[cartTitle] => Shopping Cart
[singleItem] => Item
[multipleItems] => Items
[subtotal] => Subtotal
[update] => update
[checkout] => checkout
[checkoutPaypal] => Checkout with PayPal
[removeLink] => remove
[emptyButton] => empty
[emptyMessage] => Your cart is empty!
[itemAdded] => Item added!
[priceError] => Invalid price format!
[quantityError] => Item quantities must be whole numbers!
[checkoutError] => Your order could not be processed!
)
[button] => Array
(
[checkout] =>
[paypal] =>
[update] =>
[empty] =>
)
[tooltip] => 1
[decimalQtys] =>
[decimalPlaces] => 1
[priceFormat] => Array
(
[decimals] => 2
[dec_point] => .
[thousands_sep] => ,
)
)
[items] => Array
(
[0] => 3
[1] => poslaju
)
[names] => Array
(
[3] => Hockey Stick
[poslaju] => Pos Laju
)
[prices] => Array
(
[3] => 33.25
[poslaju] => 6.00
)
[qtys] => Array
(
[3] => 1
[poslaju] => 3
)
[urls] => Array
(
[3] => http://bing.com
[poslaju] =>
)
[subtotal] => 51.25
[itemCount] => 4
)
Im using print_r($jcart) to get the result above.
i just want to print out [qtys] array. i have try print_r($qtys); but it's not working.
You have to reference the array element. So you'll always need to point to $jcart and then reference from there. As Sergey pointed out, you've got an object there
Jcart Object
So you'll have to reference the element of the object, not an array
print_r($jcart->qtys);
use the reference key for selecting that particular element u need.
echo '<pre>'; print_r($jcart->qtys);
<pre> tag is just added to view the array in a better format
I asked this question few months ago but at that time i needed to pull just one membership level, now i need to pull every level name, here is array:
Array
(
[success] => 1
[member] => Array
(
[0] => Array
(
[Levels] => Array
(
[1391447566] => stdClass Object
(
[Level_ID] => 1391447566
[Name] => Team Membership
[Cancelled] =>
[CancelDate] =>
[Pending] =>
[UnConfirmed] =>
[Expired] =>
ExpiryDate] => 1397266537
[SequentialCancelled] =>
[Active] => 1
[Status] => Array
(
[0] => Active
)
[Timestamp] => 1394588137
[TxnID] => WL-1-1391447566
)
[1391540448] => stdClass Object
(
[Level_ID] => 1391540448
[Name] => Gold Training Membership
[Cancelled] =>
[CancelDate] =>
[Pending] =>
[UnConfirmed] =>
[Expired] =>
[ExpiryDate] => 1396642789
[SequentialCancelled] =>
[Active] => 1
[Status] => Array
(
[0] => Active
)
[Timestamp] => 1393967989
[TxnID] => WL-1-1391540448
)
[1391540567] => stdClass Object
(
[Level_ID] => 1391540567
[Name] => Platinum Training Membership
[Cancelled] =>
[CancelDate] =>
[Pending] =>
[UnConfirmed] =>
[Expired] =>
[ExpiryDate] => 1397302237
[SequentialCancelled] =>
[Active] => 1
[Status] => Array
(
[0] => Active
)
[Timestamp] => 1394623837
[TxnID] => WL-1-1391540567
)
)
[PayPerPosts] => Array
(
)
)
)
[supported_verbs] => Array
(
[0] => GET
[1] => PUT
[2] => DELETE
)
)
What I need is to pull Name of Level which is inside an object that has diffrent number every time and add it to an array which i need to save in DB. One solution, just to pull info, wass:
foreach ($response["member"][0]["Levels"] AS $level_key => $level_val) {
$level_name = $level_key->Name;
echo 'Name: '.$level_name;
}
but its not pulling anything, just echoing "name" 3 times.
This was the code i used to pull only one name:
$levels = $response["member"][0]["Levels"];
$firstLevel = array_shift(array_values($levels));
$membership = $firstLevel->Name;
Thanks!
Just try with:
$level_name = $level_val->Name;
$level_key is an integer value with level ID (?). $level_val is your level object with data.
I'm working with the the fb page and I have pulled posts from a use using:
$fbapp = PVConfiguration::getConfiguration('afbapp');
$facebook = new Facebook( array('appId' => $fbapp -> app_id, 'secret' => $fbapp -> app_secret, 'cookie' => true ));
$facebook->api( $this -> fb_page_id . '/feed');
Now a sample result looks something like this:
[0] => Array
(
[id] => 311007125672751_315405295232910
[from] => Array
(
[category] => Retail and consumer merchandise
[name] => Example Demos
[id] => 311007125672751
)
[story] => Phonefare Demos added a new photo.
[story_tags] => Array
(
[0] => Array
(
[0] => Array
(
[id] => 311007125672751
[name] => Example Demos
[offset] => 0
[length] => 15
[type] => page
)
)
)
[picture] => https://fbcdn-photos-e-a.akamaihd.net/hphotos-ak-ash2/576447_315405255232904_1958203550_s.jpg
[link] => https://www.facebook.com/photo.php?fbid=315405255232904&set=a.315405251899571.62826.311007125672717&type=1&relevant_count=1
[icon] => https://static.xx.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif
[actions] => Array
(
[0] => Array
(
[name] => Comment
[link] => https://www.facebook.com/311007125672751/posts/315405295232910
)
[1] => Array
(
[name] => Like
[link] => https://www.facebook.com/311007125672751/posts/315405295232910
)
)
[privacy] => Array
(
[description] => Public
[value] => EVERYONE
[friends] =>
[networks] =>
[allow] =>
[deny] =>
)
[type] => photo
[status_type] => added_photos
[object_id] => 315405255232904
[created_time] => 2012-12-21T15:04:37+0000
[updated_time] => 2012-12-21T15:04:37+0000
[shares] => Array
(
[count] => 2
)
[likes] => Array
(
[data] => Array
(
[0] => Array
(
[id] => 45608554
[name] => Michele A
)
)
[paging] => Array
(
[cursors] => Array
(
[after] => NDU2MDg1NjY=
[before] => NDU2MDg1NjY=
)
)
)
)
My greatest point of confusion is this. I want to store the post in the database as a bigint. But the return id is
311007125672751_315405295232910
, and I'm guessing its two IDS. So which ID should I be storing in the database to reference later? What are both IDs for? Is there a fundamental flaw for breaking the IDS apart to start them as BigInts/UUIDs?