Working with an Array inside Your Theme Options Array – Multiple Values

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

how to store arrays into a database

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

WP Query for variable taxonomies

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, );

How am I able to get the value out of cookie array when I push a button?

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

How to insert new element to existing array in usermeta?

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

How to fetch an array in $wpdb?

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

Create an array with a string key from wpdb->get_results

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