New answers tagged

1

You could use wp_parse_id_list() to sanitize your comma seperated list of post IDs. It's defined as: function wp_parse_id_list( $list ) { if ( !is_array($list) ) $list = preg_split('/[\s,]+/', $list); return array_unique(array_map('absint', $list)); } where we can see that it returns unique array values as well. Note that absint() is ...


0

get_posts doesn't have a post__in "variable", that's in wp_query, in get_posts (or get_pages) you would need to use include e.g. $news = get_posts( array( 'post_type' => 'post', 'include' => $newspostids, ) ); https://codex.wordpress.org/Function_Reference/get_posts


0

Since $tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) ); returns an array, you should be able to use it like $reviewArgs = array( 'post_type' => 'game', 'meta_query' => array( array( 'key' => 'gametags', 'value' => $tag_ids, 'compare' => 'IN' ) ) ); ...


0

I don't know if you can get one array to compare to the other directly, but you can create a loop to set up a meta_query array that will check for each of the IDs within the field separately: $tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) ); $meta_query = array('relation' => 'OR'); foreach ($tags_ids as $tag_id) { ...


0

Answering my own question again. :P I finally found this Gist that lets me get and set array variables via dot notation: https://gist.github.com/elfet/4713488 So I included the DotNotation class and now my code looks like this (skipping all sorts of error checking here) : $fieldmap_string = 'key1.key2.key3.etc'; $current_page_content = ...


0

Use PHP explode function and convert string into array using a delimiter | then you can use foreach loop. Example:- $str = get_the_author_meta('my_pet', $author_id); $pets_array = explode('| ', $str); if (is_array($pets_array)) { foreach ($pets_array as $pet) { echo $pet; echo 'somtext'; echo '<br />'; } }


0

$wpdb->get_results returns a multi-dimensional array. So the argument for the foreach should be: foreach($results as $object=>$result){ echo $result->Name; } Always var_dump your objects and arrays before accessing them.


2

Going to take a wild stab, but ARRAY_A will return an associative array You are then trying to access this associative array as an object Simple change: foreach($results as $result){ echo $result->Name; } To: foreach($results as $result){ echo $result['Name']; } and the error should go away!


2

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, ...



Top 50 recent answers are included