Echo specific term in an array
It is an object, and you can use the following notation: <?php echo $myterms[0]->name; ?>
It is an object, and you can use the following notation: <?php echo $myterms[0]->name; ?>
Assuming this array for example usage: $options = array( “name” => __(‘Font’,’mytheme’), “desc” => __(‘Change the font face)’,’mytheme’), “id” => “mytheme_font”, “std” => array(‘size’ => ’10px’, ‘face’ => ‘Arial’, ‘color’ => ‘#000000’), “type” => “text”, ); For question 1, to reference nested arrays, just reference them directly. echo $options[‘std’][‘size’]; In the form input, if using … Read more
What WP does for arrays (and objects) on some contexts (such as post fields) is using maybe_serialize()/maybe_unserialize() to turn such types (and just them) to and from serialized (string-typed) representation. While this simplifies workflow it comes with penalties, such as being unable to properly query through such data and common issues with migration (seriazlization-unaware tools … Read more
tax_query requires an array of arrays, and $the_taxes is an array of arrays, you’ve already got 99% of your answer. foreach ($taxes as $tax) { $the_taxes[] = array ( ‘taxonomy’ => $tax, ‘field’ => ‘term_id’, ‘terms’ => $terms, ); } $the_taxes[‘relation’] = ‘OR’; $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => $the_taxes, );
PHP interprets those arrays differently. In the first example you’re asking WP_Query to get postsby 3 term slugs and in the second example you’re assigning the array a value of 1 string. If we were to print the two arrays it would look like this: Your Example 1: ‘terms’ => array( [0] => ‘The A … Read more
You need to put the id of each item inside form to indicate the item that will be deleted. <?php $all_favorites= unserialize($_COOKIE[‘favorites’]); echo ‘<table>’; foreach($all_favorites as $key => $value) { echo ‘<tr>’; echo ‘Post-ID = ‘ . $value . ‘ ‘; ?> <form method=”POST”> <input type=”hidden” name=”id” value=”<?php echo $value; ?>”> <button type=”submit” class=”btn btn-default” … Read more
Let’s analyze your code and what it does. Assuming that the current fruits stored in the database are ‘pineapple’ and ‘orange’, get_user_meta(2, ‘fruits’, false) will return something like this: array( array( ‘pineapple’, ‘orange’ ) ) This is because you passed false as the third argument, $single. The function returns an array if $single is false … Read more
You have a problem with your query which is you can’t use GROUP BY and ORDER BY before WHERE replace FROM tablename GROUP BY submit_time ORDER BY submit_time DESC with FROM tablename This is your query $results = $wpdb->get_results( ‘SELECT DATE_FORMAT(FROM_UNIXTIME(submit_time), “%b %e, %Y %l:%i %p”) AS Submitted, MAX(IF(field_name=”Name”, field_value, NULL )) AS “Name”, MAX(IF(field_name=”Email”, … Read more
Found the solution: $currentProducts = $wpdb->get_results(“SELECT feedid, id, size, price FROM products WHERE shopid = $shopid”, OBJECT_K); The OBJECT_K parameter makes an associative array with feedid as key: https://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results
Here’s my approach… First you have to select 3 latest posts, then you have to pick random one of them… But it’s easier to shuffle selected posts than picking only one of them – that way you can still use normal loop: <?php $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3, ‘post_status’ => ‘publish’ … Read more