How do I turn these values from MYSQL into an array
Use $wpdb->get_col. It will return a one-dimensional array that you can use in post__in $allposts = $wpdb->get_col(“SELECT `music_id` FROM `custom_table` ORDER BY id DESC LIMIT 5”);
Use $wpdb->get_col. It will return a one-dimensional array that you can use in post__in $allposts = $wpdb->get_col(“SELECT `music_id` FROM `custom_table` ORDER BY id DESC LIMIT 5”);
Your function is unreliable and totally overboard and really really expensive. Furthermore, as already stated by @MarkKaplun, you are not calling the_post() which causes the $post global not to be updated to the current post being looped through, so the value from get_post_meta() will always have the same value. Although $post_id might work, it is … Read more
You aren’t constructing the meta_query correctly. It is close but not quite right. $searchArray = array(); $searchArray = array(‘relation’ => ‘OR’,); // here is the change // loop over checked checkboxes if(!empty($_POST[‘course_location’])) { foreach($_POST[‘course_location’] as $check) { // echo ‘<h1>’.$check.'</h1>’; $searchArray[] = array(‘key’ => ‘course_location’,’value’ => $check,’compare’ => ‘LIKE’,); } } As you have it … Read more
I cannot really see doing this than to run a couple of queries here, one per category. We will need to be clever here to avoid a lot of unnecessary work. Lets look at the code; (which I will comment to ease the process of understanding) // Get the categories. We will only get the … Read more
Add ‘fields’ => ‘ids’ to skip setting up the post and just create the array you want in the foreach. $week_args = array( ‘posts_per_page’ => – 1, ‘post_type’ => ‘post’, ‘post_status’ => array( ‘publish’ ), ‘fields’ => ‘ids’, ‘date_query’ => array( ‘before’ => ‘next Saturday’, ‘after’ => ‘last Monday’, ), ); $week_array = get_posts( $week_args … Read more
How about using a standard for loop instead: $sunnytags = get_tags ($tagargs); $count = count ($sunnytags); for ($i = 0; $i < ($count < 15 ? $count : 15); $i++) { $string .= ‘<a class=”tag2″ href=”‘. get_tag_link ($sunnytags[$i]->term_id) .'”>’. $sunnytags[$i]->name . ‘</a>’; } And then later, whether you re-run the query or (better still) save … Read more
Try this : // This converts the WP_Term Object to array. $catlist = json_decode(json_encode($catlist),true); $category_id = array_column($catlist, ‘cat_ID’); print_r($category_id);
Try this Omer $fields = array( ‘author’ => ‘<div class=”form-group”><input class=”form-control” id=”author” name=”author” type=”text” placeholder=”Name ‘.( $req ? ‘*’ : ” ) .'” value=”‘ . esc_attr( $commenter[‘comment_author’] ) . ‘” ‘ . $aria_req . ‘ /></div>’, ’email’ => ‘<div class=”form-group”><input class=”form-control” id=”email” name=”email” type=”text” placeholder=”E-mail ‘.( $req ? ‘*’ : ” ) .'” value=”‘ . … Read more
get_user_meta returns an array, so to get an array containing an array of each user’s data, use [] to append: foreach( $users as $user ){ $veik[] = get_user_meta( $user->ID ); }
If you check the line from the error notice you should find in WP 4.9.1 the usage of the function array_filter, that need a array as parameter (see the code). Your value inside your array for an post need an array for ‘post_category’, is currently a string. From the source of the WP core: * … Read more