I want to use the REST API of wordpress to build a new version of a custom theme. I'm able to get the json response of a particular category, but I need to find a way to obtain also the featured image or the second post thumbnail registered using a plugin, so I can use them in the layout. Is this possible without using a plugin? here is the code I'm using for testing: <script> (function($){ $(document).ready(function(){ $.getJSON('https://localhost/wordpress/wp-json/wp/v2/posts?category_name=portfolio&per_page=50&_embed', function(response){ console.log(response); …
I'm having some troubles with CPTs defined with custom rest_namespace at register_post_type. I keep getting an 404 error at the console. The error shows that the namespace is not being changed in autosave route. WP default namespace: wp/v2 Custom namespace defined: ek/v1 I dug into the core classes to find how Wordpress handle custom namespace. The WP_REST_Autosaves_Controler define the namespace using get_post_type_object at the __construct method: ... $post_type_object = get_post_type_object( $parent_post_type ); .... $this->namespace = ! empty( $post_type_object->rest_namespace ) ? …
Developing a decoupled front-end consuming the REST API... I'm using create-react-app so can enter a proxy field corresponding to WP in my package.json and write my calls like fetch('/wp-json/v2/pages/...') if I run yarn start from the front-end directory... I'd love to actually have this theme in my wp-content/themes/my-theme directory though I'm no .htaccess god How can I make so that: Generic requests like mysite.com/jibble/jabble are handled by my SPA routing Protected routes like mysite.com/wp-admin/* and mysite.com/wp-content/uploads/* are still handled by …
I have to make calls to multiple pages of a Woocommerce product database (getting all products in one go seems to not be an option), and the looping and collection of the results isn't working as I expect. I should see an array with just under 900 objects, but all I'm seeing is an empty array. I'm very new to PHP. THe relevant code below: function get_awesome_products() { for ($count = 1; $count <= 9; $count++ ) { if ($count …
Not having access to the functions file, I can't add the function to add the featured image to the API so I need to use wp-json/wp/v2/posts?_embed. With javascript I believe it is ._embedded['wp:featuredmedia']['0'].source_url so I tried with php after using wp_remote_get, $post->_embedded['wp:featuredmedia'][0]->source_url but the error I am getting is : Cannot use object of type stdClass as array
I'm working with a third-party API that has optional filters on their API. I'm creating a block where the user has two select elements in Edit.js that are displayed on the backend of the block. They can select filters, specialty, and location, these values are then stored in attributes. Once a user changes a select, I want to fire off a PHP request using these attributes passed to the PHP function that uses wp_remote_get() to build the proxy and dump …
I am starting a bit with the REST API. If I am not completly mislead, the init action hook is also executed when its a REST API request. Now, I want to execute some code only, when it is not a REST API request. So I was looking for a command like is_rest() in order to do something like <?php if( ! is_rest() ) echo 'no-rest-request'; ?> But I couldn't find something like this. Is there a is_rest() out there?
Good morning, I need your help! I have my wordpress and woocommerce website hosted on azure, and when trying to edit a widget I get this error 'invalid JSON...' help! I already read all the forums with the different solutions, and nothing works. I already installed the classic editor, save the permalinks, it still doesn't work, it only happens with the widgets, and I only have a problem in azure, because I had it in another hosting and it worked …
I'm struggling to see if this is natively supported, or if it's not the best place to implement this functionality - in my app (Laravel) or the same side as the API (WordPress). Retrieving a single page (/about-us) via the slug is easy: /wp-json/wp/v2/pages?slug=about-us But the issue comes with retrieving a sub/child page. Consider /about-us/child-page - this works perfectly fine in WordPress but retrieving the page via the Rest API seems impossible? /wp-json/wp/v2/pages?slug=about-us/child-page /wp-json/wp/v2/pages?slug=%2Fabout-us%2Fchild-page%2F No Results. I can search for …
I need to search for wordpress posts with input slug or old slug only 1 parameter in single API. Now I'm using 2 url: 1. /wp-json/wp/v2/posts?slug=hello-world 2. /wp-json/wp/v2/posts?meta_key=_wp_old_slug&meta_value=hello-world How can I solve this problem? Wordpress version: 5.9
Wordpress doesn't natively search for tags so I need to install WP Extended Search and add post_tags as one of its parameters so whenever I search for keywords natively, posts with that tag will appear. However, when I tried searching on the wp-json REST API, that post doesn't appear. Here's an example with a post that is tagged with "technology". When I search "technology " using this json rest api url, it returns an empty array: example.com/posts?search=technology But if I …
On my website I have created a register page in react and I am using Wordpress headless with WooCommerce on it. So I was expecting to create a new user using the register page i have and as the Wordpress side is by default set to create a 'Customer" user type for any new registration. The registration is partially working. Let me explaining. To achieve the registration I have done this: On wordpress, I have installed the plugin : WP …
I want help on WP REST API I want to display Categories with a first level child with some attributes. Here how it should look like: { Parent "id": 3, "name": "Football", "slug": "football" child { "id": 5, "name": "League", "slug": "league" } } Please, anyone help me... Thanks
How to handle this endpoint /wp-json/wc/v3/products/?_fields=name,meta_data [ { "name": "Test", "meta_data": [ { "id": 478626, "key": "_wp_page_template", "value": "default" }, to achieve this? [ { "name": "Test", "meta_data": [ { "value": "default" }, I took a look at the documentation, but I didn't find anything relevant. Since meta_data is an array, this syntax DOESN'T work: /wp-json/wc/v3/products/?_fields=name,meta_data.value
I have one endpoint to create players, which is a PUT request to a certain route. While I was sending parameters via JSON, it was working fine, but now I need to upload a picture with data, so I switched to formdata format. This is the function running in the endpoint: public function put(WP_REST_Request $request) { ['foto' => $file] = $request->get_file_params(); if (!empty($file)) { if (!function_exists('media_handle_upload')) { require_once(ABSPATH . 'wp-admin/includes/image.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/media.php'); } $attachmentId = media_handle_upload('foto', …
Example: If I have a parent category 1 with child categories 2,3,4 etc instead of a call like this: /wp/v2/posts?categories=1,2,3,4 i want a call like this (imaging code) /wp/v2/posts?categories=1&includeallchilds=true that will include all articles from the child and sub-child of 1. how is this possible? I don't want my application make 2 api calls to find all childs of the categories of 1.. this query can done what i need, but i cant include this on rest api call, $args …
I have a standard rest API setup in WP. The results are displayed in an IOS App. Now the problem occurres, that single and double quotes and & are returned in the JSON as Unicode Decimal Code: eg. &#8216. All other characters seem fine. Any Ideas to that?
Is it possible to login to my different WP website from another WP website (they have different domain and host) ? Actually, I am trying to create a post on one of my site from my another site using Rest API? I don't even know if it is possible? If it is possible, can anyone please shade some light on this? I have been trying hard but I am stuck from past few days. All I am getting is 401() …