get_body_params() is always empty in POST request
The value you’re trying to send in the body is not valid JSON: { “userID” = 3 } JSON looks like this: { “userID”: 3 }
The value you’re trying to send in the body is not valid JSON: { “userID” = 3 } JSON looks like this: { “userID”: 3 }
Firstly, this isn’t a WordPress error. It’s a PHP error. WordPress is not going to return type errors. That all happens and the language level. If you used the same values outside of WordPress you’d get the same error. Regarding your specific issue, keep in mind that get_terms() will return a WP_Error object if the … Read more
You’re getting the Fatal Error because array_diff() is comparing the WP_Term objects in your array to a string, and it can’t do that. Here’s one way to fix that: Replace $topic = array_diff($topic, [“expired”]); with: $my_topic = array(); foreach ( $topic as $term ) { if ( ‘expired’ !== $term->slug ) { // Adds $term … Read more
There are a few ways you can make an integer a string. Here are 2 main ways to make that happen Type Cast – $values_x[] = (string) $series[0][‘data’][$i][0] Double Quote – $values_x[] “{$series[0][‘data’][$i][0]}” Also, you might want to check for null first and assign a default $values_x = !empty($values_x) ? $values_x : array(‘2010’); If you … Read more
It looks like you are using Advanced Custom Fields. Your “Product ID” is storing the object, instead of just the ID. Below shows you how you can access the post ID, otherwise just change your field saving option for Product ID. It’s a simple foreach statement. foreach( $pages as $page ) { echo $page[‘product_id’]->ID; }
Assuming that you have an array of post objects in $my_posts… $authids = array_unique(wp_list_pluck($my_posts,’post_author’)); What you will get are the post authors for the current page of posts, not the post authors for all of the posts. If you want the authors for all of the posts you will have run another query. To run … Read more
As Geert pointed out, your current conditional will always be true. An if() construct needs to be fed an expression. You’re feeding it a valid array, so that’s true. Always. So far this is basic PHP, regardless of whether in a WP environment or not. As can be read in Chris_O’s comment if ( is_category(‘some-cat’) … Read more
This is an inbuilt PHP function: $result = implode($input, ‘,’); (as noted by Brian’s comment.
Here is a very crude script I’ve knocked up to get what you are after: <?php require(‘wp-blog-header.php’); $posts = get_posts(‘numberposts=-1&order=ASC’); $posts_times = array(); foreach ($posts as $post) { $post_time = strtotime($post->post_date); $offset = $post_time % (60*60*24); $post_time -= $offset; $posts_times[$post_time]++; } $keys = array_keys($posts_times); $running_count = 0; $end_data = array(); for($i = $keys[0]; $i <= … Read more
You can get first item using this code <?php global $post; $the_post_ID = $post->ID; $n = get_posts(); $i=1; ?> <?php foreach ( $n as $post ) : ?> <nav id=”postNav”> <ul> <li<?php if ($i){ echo ‘ class=”current”‘; $i=0; }?>> <a href=”https://wordpress.stackexchange.com/questions/88596/<?php the_permalink(); ?>” title=”<?php printf( esc_attr__( ‘Permalink to %s’, ‘twentyten`enter code here`’ ), the_title_attribute( ‘echo=0’ … Read more