I have a taxonomy parent tid '8'
I need to get all child tid for this parent id
$tid = 8;
$children = taxonomy_get_children($tid);
print_r($children);
am getting this result
8
Array
(
[9] => stdClass Object
(
[tid] => 9
[vid] => 3
[name] => Domestic
[description] => Domestic
[weight] => 0
)
[12] => stdClass Object
(
[tid] => 12
[vid] => 3
[name] => Economic
[description] => Economic
[weight] => 1
)
[11] => stdClass Object
(
[tid] => 11
[vid] => 3
[name] => International
[description] =>
[weight] => 2
)
[10] => stdClass Object
(
[tid] => 10
[vid] => 3
[name] => Social
[description] =>
[weight] => 3
)
)
how can I display only tid from this array.
$children = array_keys(taxonomy_get_children($tid));
You will notice it's an associative array where the tid in the object is the same as the array key - just grab the keys, it's equivalent to grabbing the tids from the objects themselves.
Related
I'm looking for way to get a specific Gutenbergblock from my post content to use in the archive template. Somewhere in my single post there's an iconlist (nested in a column and the column nested in a row) that I would like to use as a summary of the page in the entry on the archive page.
I wrote this code to search for the block called 'kadence/iconlist' and render it.
<?php $post_id = get_the_ID();
$post = get_post($post_id);
$blocks = parse_blocks($post->post_content);
foreach ($blocks as $block) {
if ($block['blockName'] == 'kadence/iconlist') {
echo render_block($block);
}
} ?>
This renders nothing because the 'kadence/iconlist' is nested. A var_dump of the $block shows this structure:
Array
(
[blockName] => kadence/rowlayout
[attrs] => Array
(
[uniqueID] => _94b9e4-63
[columnGutter] => wider
[colLayout] => equal
[maxWidth] => 1220
[topPadding] => 55
[bottomPadding] => 55
[overlayFirstOpacity] => 1
[overlaySecondOpacity] => 1
[overlayOpacity] => 90
[align] => full
[firstColumnWidth] => 50
[secondColumnWidth] => 50
)
[innerBlocks] => Array
(
[0] => Array
(
[blockName] => kadence/column
[attrs] => Array
(
[topPadding] => 25
[bottomPadding] => 25
[leftPadding] => 25
[rightPadding] => 25
[uniqueID] => _91ffee-25
)
[innerBlocks] => Array
(
[0] => Array
(
[blockName] => kadence/advancedgallery
[attrs] => Array
(
[uniqueID] => _ccc1ba-38
[columns] => Array
(
[0] => 2
[1] => 2
[2] => 2
[3] => 2
[4] => 1
[5] => 1
)
[thumbSize] => full
[ids] => Array
(
[0] => 355
[1] => 354
[2] => 357
[3] => 353
[4] => 351
[5] => 352
[6] => 349
[7] => 348
[8] => 350
)
[type] => thumbslider
[imageRatio] => square
[linkTo] => media
[gutter] => Array
(
[0] => 40
[1] =>
[2] =>
)
[imageRadius] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
)
[autoPlay] => 1
[autoSpeed] => 4000
[lightbox] => magnific
[margin] => Array
(
[0] => Array
(
[desk] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
)
[tablet] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
)
[mobile] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
)
)
)
[thumbnailRatio] => square
[thumbnailColumns] => Array
(
[0] => 4
[1] => 4
[2] => 4
[3] => 4
[4] => 4
[5] => 4
)
)
[innerBlocks] => Array
(
)
[innerHTML] =>
Previous
Next
Previous
Next
[innerContent] => Array
(
[0] =>
Previous
Next
)
)
)
[innerHTML] =>
[innerContent] => Array
(
[0] =>
[1] =>
[2] =>
)
)
[1] => Array
(
[blockName] => kadence/column
[attrs] => Array
(
[id] => 2
[uniqueID] => _b56b72-c0
)
[innerBlocks] => Array
(
[0] => Array
(
[blockName] => kadence/advancedheading
[attrs] => Array
(
[level] => 1
[uniqueID] => _1f94db-5b
)
[innerBlocks] => Array
(
)
[innerHTML] =>
RVS-200HD+
[innerContent] => Array
(
[0] =>
RVS-200HD+
)
)
[1] => Array
(
[blockName] => kadence/iconlist
[attrs] => Array
(
[items] => Array
(
[0] => Array
(
[icon] => fe_check
[link] =>
[target] => _self
[size] => 20
[text] => Voordeel nummer 1 iets met emmers
[width] => 2
[color] =>
[background] =>
[border] =>
[borderRadius] => 0
[borderWidth] => 1
[padding] => 5
[style] => default
)
[1] => Array
(
[icon] => fe_check
[link] =>
[target] => _self
[size] => 20
[text] => Puntje 2
[width] => 2
[color] =>
[background] =>
[border] =>
[borderRadius] => 0
[borderWidth] => 1
[padding] => 5
[style] => default
)
[2] => Array
(
[icon] => fe_check
[link] =>
[target] => _self
[size] => 20
[text] => Puntje 3, deze zijn per bericht gewoon aan te passen
[width] => 2
[color] =>
[background] =>
[border] =>
[borderRadius] => 0
[borderWidth] => 1
[padding] => 5
[style] => default
)
[3] => Array
(
[icon] => fe_check
[link] =>
[target] => _self
[size] => 20
[width] => 2
[color] =>
[background] =>
[border] =>
[borderRadius] => 0
[borderWidth] => 1
[padding] => 5
[style] => default
[text] => En toe te voegen
)
)
[listCount] => 4
[uniqueID] => _342687-70
)
[innerBlocks] => Array
(
)
[innerHTML] =>
Voordeel nummer 1 iets met emmers
Puntje 2
Puntje 3, deze zijn per bericht gewoon aan te passen
En toe te voegen
[innerContent] => Array
(
[0] =>
Voordeel nummer 1 iets met emmers
Puntje 2
Puntje 3, deze zijn per bericht gewoon aan te passen
En toe te voegen
)
)
[2] => Array
(
[blockName] => core/block
[attrs] => Array
(
[ref] => 918
)
[innerBlocks] => Array
(
)
[innerHTML] =>
[innerContent] => Array
(
)
)
)
[innerHTML] =>
[innerContent] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
)
)
)
[innerHTML] =>
[innerContent] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
)
)
Array
(
[blockName] =>
[attrs] => Array
(
)
[innerBlocks] => Array
(
)
[innerHTML] =>
[innerContent] => Array
(
[0] =>
)
)
How do I have to change the if($block['blockName'] == 'kadence/iconlist' to actually get to the kadence/iconlist block?
I override a function from woocommerce like this :
//Declarre custom function
function custom_add_cart_item($cart_item) {
print_r($cart_item);
return $cart_item;
}
When I print $cart_item, I want to retrieve [price] => 190 (last line)
Array ( [addons] => Array ( [0] => Array ( [name] => Nombre de pension - Simple [value] => 0 [price] => 0 [wc_booking_block_qty_multiplier] => 1 ) [1] => Array ( [name] => Nombre de pension - Demi-pension [value] => 1 [price] => 30 [wc_booking_block_qty_multiplier] => 1 ) [2] => Array ( [name] => Nombre de pension - Complete [value] => 0 [price] => 0 [wc_booking_block_qty_multiplier] => 1 ) [3] => Array ( [name] => Nombre de supplément - Petit-déjeuner [value] => 0 [price] => 0 [wc_booking_block_qty_multiplier] => 1 ) [4] => Array ( [name] => Nombre de supplément - Lit supplémentaire [value] => 0 [price] => 0 [wc_booking_block_qty_multiplier] => 1 ) ) [booking] => Array ( [_year] => 2016 [_month] => 1 [_day] => 30 [_persons] => Array ( ) [_date] => 2016-1-30 [date] => 30 janvier 2016 [_time] => [_qty] => 1 [_duration_unit] => night [_duration] => 1 [duration] => 1 night [_start_date] => 1454112000 [_end_date] => 1454198400 [_all_day] => 0 [_cost] => 80 [_booking_id] => 646 ) [product_id] => 411 [variation_id] => 0 [variation] => Array ( ) [quantity] => 1 [data] => WC_Product_Accommodation_Booking Object ( [availability_rules:WC_Product_Booking:private] => Array ( ) [id] => 411 [post] => WP_Post Object ( [ID] => 411 [post_author] => 1 [post_date] => 2016-01-27 10:55:23 [post_date_gmt] => 2016-01-27 10:55:23 [post_content] => [post_title] => Produit de test [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => produit-de-test [to_ping] => [pinged] => [post_modified] => 2016-01-27 16:04:41 [post_modified_gmt] => 2016-01-27 16:04:41 [post_content_filtered] => [post_parent] => 0 [guid] => http://xxx.xxx [menu_order] => 0 [post_type] => product [post_mime_type] => [comment_count] => 0 [filter] => raw ) [product_type] => accommodation-booking [shipping_class:protected] => [shipping_class_id:protected] => 0 [total_stock] => [supports:protected] => Array ( ) [wc_booking_duration_type] => customer [wc_booking_duration_unit] => night [wc_booking_duration] => 1 [manage_stock] => no [stock_status] => instock [price] => 110 ) )
Sorry for that ugly array..
I don't know how to retrive this value. Thanks for your help !
I do this for get the category name and i got the array
Array ( [0] => stdClass Object ( [term_id] => 4 [name] => cinematography [slug] => cinematography [term_group] => 0 [avhec_term_order] => 1 [term_taxonomy_id] => 4 [taxonomy] => category [description] => [parent] => 0 [count] => 11 [object_id] => 2526 [cat_ID] => 4 [category_count] => 11 [category_description] => [cat_name] => cinematography [category_nicename] => cinematography [category_parent] => 0 ) )
For this i wrote
$category = get_the_category();
print_r($category);
Now how can i store the "[name] => cinematography" in a variable.
I assume $category is the array you got there, then
$cinematography = $category[0]->cinematography;
https://drupal.org/node/1245956
my content type, plan to have one or more 'maps'.
With the following php code, I can take all their link:
<?php print render($content['field_mappe_di_riferimento']); ?>
and I get the following result:
I would like to put before the link the image that is within the content type "Mappa", entered in the field "field_immagine_min."
this is the structure of my content type:
this is the content type "Mappa":
with: "print_r($field_mappe_di_riferimento);" I get it:
Array ( [0] => Array ( [nid] => 30 [access] => 1 [node] => stdClass Object ( [vid] => 30 [uid] => 1 [title] => Carta di Marignano, primo giorno, 13 Settembre 1515 [log] => [status] => 1 [comment] => 1 [promote] => 1 [sticky] => 0 [nid] => 30 [type] => mappa [language] => en [created] => 1352066743 [changed] => 1352127342 [tnid] => 0 [translate] => 0 [revision_timestamp] => 1352127342 [revision_uid] => 1 [field_battaglia_di_riferimento] => Array ( [und] => Array ( [0] => Array ( [nid] => 2 ) ) ) [field_immagine_std] => Array ( [und] => Array ( [0] => Array ( [fid] => 23 [alt] => [title] => [width] => 672 [height] => 554 [uid] => 1 [filename] => polesella.jpg [uri] => public://polesella_0.jpg [filemime] => image/jpeg [filesize] => 337755 [status] => 1 [timestamp] => 1352066743 [rdf_mapping] => Array ( ) ) ) ) [field_immagine_min] => Array ( [und] => Array ( [0] => Array ( [fid] => 24 [alt] => [title] => [width] => 150 [height] => 110 [uid] => 1 [filename] => polesella_small.jpg [uri] => public://polesella_small.jpg [filemime] => image/jpeg [filesize] => 10672 [status] => 1 [timestamp] => 1352066743 [rdf_mapping] => Array ( ) ) ) ) [field_testo_opzionale] => Array ( [und] => Array ( [0] => Array ( [value] => pisello [format] => [safe_value] => pisello ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item 1 => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date 1 => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1352066743 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => ant [picture] => 0 [data] => b:0; ) ) )
so I tried to take the nid of the node that I want to take the picture, with success:
print ($content['field_mappe_di_riferimento']['#items'][0][nid]);
I get 30...
I found the solution:
$array = $content['field_mappe_di_riferimento']['#items'];
$k = 0;
foreach($array as $k => $v){
print($k);
//carico il nodo
$node = node_view(node_load($content['field_mappe_di_riferimento']['#items'][$k]['nid']));
//stampa l'img del nodo
print render($node['field_immagine_min']);
}
I need to hide only one of the 2 children of a fieldset element.
I have an issue with the assigning the #type='hidden' value to 2 children elements of a fieldset.
In other words I have:
Array
(
[4] => Array
(
[#type] => hidden
[#title] => Distribution Product
[#default_value] => Array
(
)
[#options] => Array
(
[] => - None selected -
[0] => stdClass Object
(
[option] => Array
(
[38] => Cosmetics
)
)
[1] => stdClass Object
(
[option] => Array
(
[39] => Hair
)
)
)
[#description] =>
[#multiple] => 0
[#size] => 0
[#weight] => 0
[#theme] => taxonomy_term_select
[#required] => 0
)
[1] => Array
(
[#type] => select
[#title] => Product
[#default_value] => Array
(
[0] => 26
)
[#options] => Array
(
[] => - None selected -
[0] => stdClass Object
(
[option] => Array
(
[28] => Cosmetics
)
)
[1] => stdClass Object
(
[option] => Array
(
[26] => -Joelle Ciocco
)
)
)
[#description] =>
[#multiple] => 0
[#size] => 0
[#weight] => 0
[#theme] => taxonomy_term_select
[#required] => 0
)
[#type] => fieldset
[#title] => Vocabularies
[#collapsible] => 1
[#collapsed] =>
[#weight] => -3
[#tree] => 1
)
I'm currectly assigning
$form['taxonomy'][4]['#type'] = 'hidden';
$form['taxonomy'][1]['#type'] = 'hidden';
But they are both visible.
Of course if I hide
$form['taxonomy']['#type'] = 'hidden';
it works and I hide everything.
thanks
What if you try
unset($form['taxonomy'][4]);