WP API Ignoring parameters - wordpress

I have a function that loops through my products and creates some json files. Recently this function stopped working correctly.
I tracked it down to the fact the call to the WP API is ignoring the per_page parameter and always grabbing just the first 10.
$response = wp_remote_get($api_url . '/wp-json/wp/v2/products?per_page=50');
I have tried multiple parameters, like adding an offset, nothing works. It grabs the first 10 and that is it.
Has something changed? I tried Googling and I don't find anything relevant. The API documentation says this should work.
If I just put that url with the request in the browser address bar I get the 50.

Related

Here API | MultiValueQueryParameter for Via Points

I'm using the latest version of the here javascript sdk 3.1.32.0
When I use H.service.Url.MultiValueQueryParameter for my via points like
{
...,
via: new H.service.Url.MultiValueQueryParameter(['50.1234,8.7654', '51.2234,9.1123']);
}
I see in the URL params of my request this: &via=%5Bobject%20Object%5D
Someone an idea why this happens?
Thanks in advance!
When you use "via" parameter, you define a list of via waypoints. A via waypoint is not a native datatype recongnized by JavaScript, therefore, you will see in the URL params the word object refering to a particular data structure, in this case the via Waypoint composed mainly by Latitude, Longitude.
Regards.
This took a while to figure out the actual issue with the malformed url params. I was dynamically loading the here maps service script on mount of a component. Accidentally this happened in some cases twice. In both cases H was globally available and everything worked like expected. BUT when the script was loaded twice H.service.Url.MultiValueQueryParameter didn't return the correct params. It basically encoded them twice, or tried to.
The other side issue was that https://www.npmjs.com/package/#types/heremaps is outdated and doesn't cover MultiValueQueryParameter. So I had to remove the types and use my own. Else I probably would have realized the issue earlier.

WP Rest API: Can't seem to get embedded data from the post object

I am working with the WORDPRESS REST API and Wordpress version 4.8 for an internal network page at a local office. We have permalinks disabled (security reasons) and thus I am accessing the posts object like so:
https://url/blogs/usernamehere/?rest_route=/wp/v2/posts/12345
I am able to do a GET request and can get the posts data into my view template with no issues. However, I can't seem to figure out how to consume additional content in the post object . I have followed the documentation and tried to do:
https://url/blogs/usernamehere/?rest_route=/wp/v2/posts/12345?_embed=true
But, I get a STATUS 404 .
How would I correctly apply the embed function in the URL so I can get the additional data associated with the post?
Pass the _embed global parameter without a value, per the documentation.
you should do this:
https://url/blogs/usernamehere/?_embed=true&rest_route=/wp/v2/posts/12345
Basically you add _embed=true at before other parameters and after & add other parameters.

Wordpress feed - (A feed could not be found at)

I had set up two Wordpress development sites, URL's were something like mysite.com/dev/blog1 and mysite.com/dev/blog2. blog2 would fetch posts from categories on blog1 using fetch_feed() e.g. fetch_feed(mysite.com/dev/blog1/category/fun/feed) and everything worked fine.
However, since moving the sites over to mysite.com/blog1 and mysite.com/blog2, the feed does not work. I get the following error:
A feed could not be found at mysite.com/blog1/category/fun/feed. A feed with an invalid mime type may fall victim to this error, or SimplePie was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed." } } ["error_data"]=> array(0) { } }
When I go to the feed URL though, the feed does exist.
Any ideas?
The fetch_feed() function is still trying to look at the dev. Highlighted below:
"A feed could not be found at mysite.com/dev/blog1/category/fun/feed. A feed with an invalid mime type may fall vic....."
You will need to remove the dev part from the url.
Had the same problem. I've tried different Wordpress RSS plugins and got the same result: "RSS Error: A feed could not be found at ..."
(For almost all RSS feeds except for feeds from feedburner!)
I contacted our provider / web hosting service, they "unlocked" the domain of the rss feed within a minute and now it works perfectly!
If you're using a webhoster, maybe you need to contact their support for help.

Wordpress Loop get_the_id()

I tried the following functions in header.php, footer.php, single.php etc.
var_dump(in_the_loop());
var_dump(get_the_id());
The first function gives false (meaning we are not in the loop) and the second function gives the post id every single time.
Description of get_the_id() from wordpress :
Retrieve the numeric ID of the current post. This tag must be within The Loop.
I just want a simple explanation what the hell is going on why do i get the post id if I call the function out of the loop !?
must is a little strong for get_the_id() ...delivers evil eye to Wordpress.
It works in the header and non-loop (confirmed).
Please note that post/page are essentially interchangeable in this conversation.
Think of WP this way -> You always have a post id in some way, all the time, every page, unless you do weird stuff or talk about non-page edge cases. When you are at the install root (such as site.com/) there are posts being called, something has to be displayed. There are other settings that will impact post/page such as static front page settings. On a category listing, if there are pages, I got the first ID returned before the loop.
On post/pages the page ID is (more or less0 set before the loop. This is a result of the URL (pretty or ?p=123 format) dictating the content. Using pretty names, the page at site.com/foo-bar/ will try to look up if there is content available via the permalink rules for "foo-bar". If there is content, the post ID is obtained. (simplified)
Later in the page build you get into the loop. However, before the loop you are also offered opportunities to change, sort, or augment the loop - such as changing the page IDs to be looped or sorting.
Regarding in_the_loop(), WP says
"True if caller is within loop, false if loop hasn't started or has ended." via http://codex.wordpress.org/Function_Reference/in_the_loop
in_the_loop() evaluates if the loop is in action (loop being key to the WP world). Also important - when you are in the loop WP can iterate over multiple page/post (IDs).
I don't have a 100% bulletproof explanation as to how the ID always shows, but when you dig into the API and various methods for hooking this might be a result.
I understand your confusion and agree with you. I think WP intended get_the_id() as a loop based tool, outside the loop you will get unpredictable results.
Hope that helps, I do enjoy working in WP, and I hope you do to.

Wordpress and FeedBurner Error

I used to use FeedSmith FeedBurner Plugin for my wordpress. Today, suddenly, my feeds are giving following errors under each Post Title. I recently upgrade to WP 3.0.1 but has been a week.
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'Array' was given in /home/name/wordpress/wp-includes/plugin.php on line 166
I deactivated the plugin and install new plugin "FD Feedburner Plugin" and try again but still no luck. The error still persist even on FeedBurner Page.
Any idea please?
Hopefully you have this fixed already. But I'd like to throw some thoughts on this since it remains unanswered. It appears that 50 people have come here since you posted 7 months ago so maybe I can help someone looking to resolve this or a similar problem. My answer is not specific to FeedBurner or even Wordpress.
The call_user_func_array function takes a string or an array as the first parameter and this parameter determines what function/method call will be made. In the case that the first parameter is an array then the method name should actually be the second element of the array and the first element should be the class name that contains the method.
For example:
call_user_func_array(array($class_name, $method_name), $params)
Because your error is saying that "'Array' was given" I can only assume that the first parameter passed to the function is either an empty array, the first parameter is an array with the first element being an empty array, or somewhere earlier in the code the class or function name was converted to a string as an array.
The same error message can result if the first function parameter is an empty array
Both of the following BAD examples will give the "'Array' was given" error:
call_user_func_array(array(), $params);
call_user_func_array(array(array(), 'method_name'), $params);
So if nothing else, you know that first parameter in the call_user_func_array function call is not what it needs to be.
Hope it helps!

Resources