My guess is that you’re accessing $response
as an array when it’s a \WP_Error
. Check out the possible return values of wp_remote_post
:
(array|WP_Error) The response or WP_Error on failure.
You should modify your code in a couple of ways:
$response = wp_remote_post( $remote_url, $request );
if ( is_wp_error( $response ) ) {
// handle the error response here.
}
$body = wp_remote_retrieve_body( $response );
if( false !== strlen( $body ) ) {
This ensures you catch any \WP_Error
returns and gets the body data using wp_remote_retrieve_body
. You can also use wp_remote_retrieve_response_code( $response )
to get the HTTP status code (e.g. 200
, 401
, etc.)
Related Posts:
- WP JSON REST API (Ryan McCue) how to query posts with specific meta data with ‘AND’ relation?
- Creating two database tables via plugin
- Query Posts by Custom Field ‘Price’
- WP_query parameters for date range
- insert data in database table from plugin with WP3.1
- Thumb rating for wordpress – top user
- Comparisson between date() and a date from wp_postmeta
- Find out if request is for custom post type archive before query runs
- How to extract images of post and pages excluding header and logo image in wordpress?
- Fatal error: Uncaught Error: Call to undefined function get_userdata()
- Is it possible to filter the wp_footer() scripts, read the content, and insert them inline?
- Can I run multiple queries with $wpdb->prepare?
- How use %like% in sql statement wordpress
- medoo framework in WP plugin
- WordPress logo upload option in theme panel
- Accessing GET variable named ‘error’
- FacetWP group listings by custom field [closed]
- How can i list random post from multiple category?
- how do i remove posts from a WP_Query so the pagination is right?
- Accessing post’s meta data based on user’s click of a post
- WooCommerce shop page orderby [closed]
- Get posts from WP_Query and format them on admin_head
- Not getting author rank when using return
- How to query the custom fields by language?
- switched from query_posts to WP_query, not working now?
- AJAX search posts and pages
- DROP TABLE with uninstall hook not working
- How to change this WP_Query to get all ProductIDs and not only specific one?
- How to call WordPress function other files
- Insert content of a post into another
- WP_Query and NULL meta keys
- how to use in custom single.php template using php?
- WordPress page and plugin list using sql query
- How to create a custom shortcode based on the layout?
- Using AJAX to generate front end / viewer end pages
- WooCommerce search products between price range using WP_Query
- ACF: post query, hide duplicate values [closed]
- Redirect to another page using contact form 7? [closed]
- How to insert multiple postmeta values with one query?
- How to Loop Through all Posts and Count Attachments using Get Media Attachments
- order posts by `meta_key`, Does not display posts that does not have `meta_key`
- Replacing global wp_query
- Error in pdf generating plugin using FPDF
- Return multiple values in a shortcode attribute
- woocommerce search by sku and title ajax
- Loop returns the current page’s permalink and guid instead of the post in the loop
- Add user meta after a user has registered and logged In [closed]
- How to get CPT category checkbox list and show post of selected(multiply) checkboxes via ajax?
- BuddyPress activity on edit post for a CPT
- Delete data from custom table when deleting a post
- Pagination not working
- How to find the WordPress Nextgen galleries which are not used in WordPress posts?
- Adding CASE in WP_Query
- Searching a tab/space delimited text file based upon form criteria and returning a ‘record’ into a word press results page
- Woo-commerce Update price as a Bulk from My offline software export
- How to search post titles with whole words only, but not the exact word only?
- Trying to get property ‘ID’ of non-object in /wp-includes/class-wp-query.php on line 4044
- Use get_pages() before another plugin modifies it
- how to display recent post by category on home page
- How to Join wp_posts & wp_postmeta table using custom query
- What database state changes happen after a post is manually “updated” with no changes?
- any word search WordPress
- Warning: call_user_func_array() problem can anyone help with it?
- adding dynamic/multiple slug values in ‘option_none_value’
- How to get a specific string from a url
- WooCommerce Product Table – filter query on attributes
- Performance considerations – postmeta table versus new table for custom posts with foreign keys?
- How to pass multiple custom fields as shortcode’s parameters
- Checkbox field that add a subscription product and change prices of other products in checkout and cart page
- Is it possible to custom set query for a WordPress REST API response?
- Only return taxonomies that are linked to a category & product
- How to add specific posts to specific pages in WordPress?
- How to use information from the database in the front-end?
- User Following System
- How to fix slow comment query?
- ACF Query result in a new td (echo)
- Multiple Meta key in search
- History of page, interval of years
- How to insert variable which contain array value in wp_options table?
- Trending Tags based on post views
- Shortcode in a blog post, footer and related products stop working
- Plugin does not create a custom table upon activation
- How to delete only user meta value (not key) from usermeta table in wordpress?
- How can i see/log all requests coming from a registration form (not from the UI)?
- w3 total cache and post__not_in
- Action hook “wp_insert_post” works but not for last imported post
- WP_Query Date Filtering Inclusive Being Ignored
- Second foreach loop breaking (Posts2Posts)
- Advanced Custom Fields (ACF) Plugin – Random Image in Sidebar
- Ger posts from similar tags and categories
- WordPress filter function using query modifications
- WP-Snap too slow (caused by WP_Query?)
- WordPress Meta Query: Relation is not working correctly
- WordPress ultra slow if I click on posts?
- Insert data in custom table during new post creation
- Making a Custom Post Type Publish Loop
- Checking url from plugin [duplicate]
- I want to display data last 7 days with date wise in chartjs?
- Order custom post type by posts with most likes first
- Accessing Correct Database to Create REST API Endpoint