array_rand not working correctly?

Getting a single random post would be far more efficient than getting all posts, then plucking a random post from the query. Here’s an updated WP_Query instance using ‘orderby’ => rand: $args = array( ‘orderby’ => ‘rand’, ‘posts_per_page’ => ‘1’, ‘paged’ => $paged, ‘post_type’ => ‘Didyouknows’, // Post type names should never use capital letters, … Read more

Separate array output into a

The foreach loop isn’t needed. This will list out all job categories separated by a comma. $terms = wp_get_post_terms( $job->ID, ‘job_listing_category’ ); echo implode( ‘, ‘, wp_list_pluck( $terms, ‘name’ ) ); // Marketing, Sales, Finance, Support

Multidimensional Array

The multidimensional array in this case is a multi-dimensional associative array, or a key-value pair. The key being ‘status’ and the value being your array of strings. In the conditional check you have attempted to access values by a numerical index, which in this case do not exist as nothing has been set to use … Read more

How can I split my query result in 2 arrays?

There’s no need to split the array, you can just close the first div once you’ve counted up to four elements of the array. $args = array( ‘post_type’ => ‘event’, ‘meta_key’ => ‘date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘posts_per_page’ => 8, ‘meta_query’ => array( ‘key’ => ‘date’, ‘value’ => date(‘Y-m-d’,strtotime(“today”)), ‘compare’ => ‘>=’, ‘type’ … Read more

Output category list inside array

Try something like the following. Notice that the hide_empty argument is set to false. $args = array( ‘orderby’ => ‘id’, ‘hide_empty’=> false, ); $cats = get_categories($args); foreach ($cats as $cat) { // Your code to populate new array here } And then assign your newly created array to values.

Do not replicate items if they exists in a foreach loop

Just set a flag to check for a new value, and only display the date if the new value does not match the flag, like so: <?php $args = array( ‘post_type’ => ‘tv-schedule’, ‘posts_per_page’ => -1, ‘orderby’ => ‘date’, ‘order’ => ‘ASC’, ‘post_status’ => array(‘publish’, ‘future’), ); $posts_array = query_posts($args); $flag = ”; // set … Read more

construct complex queries with WP User Query

$meta_query_args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, // Optional, defaults to “AND” array( ‘key’ => ‘_my_custom_key’, ‘value’ => ‘Value I am looking for’, ‘compare’ => ‘=’ ), array( ‘relation’ => ‘AND’, array( ‘key’ => ‘_my_custom_key_2’, ‘value’ => ‘Value I am looking for 2’, ‘compare’ => ‘=’ ), array( ‘key’ => ‘_my_custom_key_3’, ‘value’ => … Read more