WordPress text field in array problem

It looks like you may be creating an array around a single long string that needs to be split up into array elements (assuming $idsposts is a string and not an array). Try using $myposts = explode(“,”, $idsposts); Instead of just adding $idsposts as the only element of your $myposts array. You can also check … Read more

How to assign results to variables?

Best luck while you learn. $fivesdrafts = $wpdb->get_results( ” SELECT ID, post_title FROM $wpdb->posts WHERE post_status=”draft” AND post_author = 5 ” ); foreach ( $fivesdrafts as $fivesdraft ) { echo $fivesdraft->post_title; } This example has been sponsored by WordPress codex. In your case $wpdb->get_results( Should become like: $variable_to_print = $wpdb->get_results(

date_query problem

You’re looking for the get_adjacent_post function. This is a built-in wordpress function that you can use to get either the previous or next post from the current post. To get the next post: $next_post = get_adjacent_post( false, ”, false, ” ); To get the previous post: $prev_post = get_adjacent_post( false, ”, true, ” ); You … Read more

Convert Custom Post Data to Javascript Array for Autocomplete

$args = array( ‘post_type’ => ‘promo’ ); $loop = new WP_Query( $args ); $promos = array(); while ( $loop->have_posts() ) : $loop->the_post(); foreach((get_the_category()) as $category); $promos[] = $category->cat_name. ‘ – ‘ .get_the_title(); endwhile; echo ‘<script> jQuery(document).ready(function($) { var promoList=”.json_encode($promos) .”; $( “#auto-promo” ).autocomplete({ source: promoList }); }); </script>’;

wp_set_object_terms not accepting variable array

Ok, so it turned out that my array was an array of strings somehow, which using var_dump (instead of print_r) revealed. Then I needed to convert my array to int values, which I did thus: $myissuearrayINT = array_map(‘intval’, $myissuearray); And now, when I do the following it works as expected: wp_set_object_terms( $myID, $myissuearrayINT, ‘my_issues’, true … Read more