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

How can I pick a single post from the latest 3?

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

How can I get an array of all IDs from the current queried object?

You are overwriting $post_ids variable on every while loop, never collecting them. That can be solved using $post_ids = array(); while (have_posts()) : the_post(); $post_ids[] = get_the_ID(); endwhile; var_dump($post_ids); // this is an array of ids However there is simpler way, you can skip the whle cycle and simply run: if( function_exists( ‘wpseo_local_show_map’ ) && … Read more

Multiple User-Meta Values in One User-Meta Key

If you check out the documentation for the update_user_meta() function, you’ll note that the $meta_value parameter already accepts objects and arrays, so you can simply save a user’s positions in an array without any additional effort: update_user_meta( 22, ‘position_names’, array( ‘Khaleesi of the Great Grass Sea’, ‘Breaker of Chains’, ‘Mother of Dragons’ ) ); The … Read more

Replace text inside a huge multidimensional array

Try this php built-in function array_walk_recursive function wpse_do_something_on_data() { $data = array( ‘repeater-1’ => array( array( ‘user_defined_field1’ => ‘http://www.domain-001.com’, ‘user_defined_field2’ => ‘http://www.domain-002.com’, ), array( ‘user_defined_field1’ => ‘http://www.domain-011.com’, ‘user_defined_field2’ => ‘http://www.domain-012.com’, ), ), ‘repeater-2’ => array( array( ‘user_defined_field1’ => ‘http://www.domain-101.com’, ‘user_defined_field2’ => ‘http://www.domain-102.com’, ), array( ‘user_defined_field1’ => ‘http://www.domain-111.com’, ‘user_defined_field2’ => ‘http://www.domain-112.com’, ), ), ); array_walk_recursive( $data, … Read more