How to set category correctly for a custom post created by a remote API call?

I'm using a plugin - "cleverness-to-do-list" (https://wordpress.org/plugins/cleverness-to-do-list/#description ). I'm aware that the plugin is closed, but I've updated it at my end and gotten it working with my self-hosted Wordpress edition (version 6). I'm trying to create a setup where a remote server calls a webpage on my server and POSTs some data. That custom PHP webpage is configured to create a new ToDo item (which is placed in the posts table). It does that fine except for setting the …
Category: Web

.htaccess and proxy settings for routing a decoupled REST API consuming theme

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 …
Category: Web

Show only images and videos in a wp.media window

I'm using the following JS code to open a wp.media window to allow users to select images and videos for a gallery. Everything is working as expected, but I'm unable to restrict the window to show images and videos only, it's showing everything. Any ideas on what might be wrong? Thanks in advance JS: $( '#add_item' ).on( 'click', function( e ) { var $el = $( this ); e.preventDefault(); // If the media frame already exists, reopen it. if ( …
Category: Web

How To Save Data From Remote APIs To ACF?

I've been attempting to ingest remote data from an api partner into Wordpress. To data I've used wpallimport plugin, but it's quite limited. How would one connect with a remote api and then save the data to a an ACF field either one time or periodically? I've test out wp_remote_get($apiUrl); and even created a POC but saving the data to the WP database has not been successful yet.
Category: Web

Why does wp_remote_post returns an empty body response on certain endpoints?

Im gonna make this brief; Im using wp_remote_post to do a POST request to an external API. My local development environment looks something like "http://website.test". As of now I am requesting to a QA version of this API so the protocol of the endpoints is HTTP. The problem is that the $response object always returns an empty body. If I copy the exact request JSON that im sending over, and the exact HTTP URL of the API, and use it …
Category: Web

Working with a json feed & trying to figure out how best to import

Good morning all, I need to be able to import a json product feed on a daily basis to update our products and stock. I am starting to write a plugin to make this work, but have a couple of questions if somebody could please advise? (I'm relatively new to Wordpress) Here is a sample of the json I need to import: { "Type": "Air Pistol", "Mechanism": "CO2", "Calibre": "4.5mm BB", "Make": "ASG", "Model": "SCHOFIELD", "Variant": "GREY", "Origin": null, "Orientation": …
Category: Web

Defer Code in Widgets - Page Speed

How to UP Page Speed With Widget Defer? Is there a way to defer a widget in the footer? I have an external API in a footer widget which is slowing down my page. It is not needed until the page is loaded. The caching plugin I use (W3 Total Cache) gives me the option to defer other scripts, but not scripts directly coded into the widget. What is the best way to manually defer custom code API that is …
Category: Web

wp_remote_get() returns 403 while file_get_contents() does not

We are working on a WordPress plugin and we require an API call. We are using the api: http://www.geoplugin.net/json.gp?ip=8.8.8.8 In this context: $response = wp_remote_get("http://www.geoplugin.net/json.gp?ip={$ip}", array( 'timeout' => 45, 'redirection' => 5, 'user-agent' => 'Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)', )); $dataArray = json_decode(wp_remote_retrieve_body($response)); var_dump($response); However, all we get is a 403 error saying: string(162) " 403 Forbidden nginx " The API call worked fine using this code: file_get_contents("http://www.geoplugin.net/json.gp?ip={$ip}") However, we are only allowed to use wp_remote_get() by WordPress. We have been …
Category: Web

Creating a post with the REST API, curl and oauth returning 401 error

I'm trying to create a WordPress post using the REST API, OAuth, and cURL. However, I'm running into some trouble. I'm able to create a blank post (no title, slug, etc) using the following code: $header = array(buildAuthorizationHeader($oauth), 'Expect:'); $options = array( CURLOPT_HTTPHEADER => $header, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_POST => true, CURLOPT_URL => $url, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false); This works as expected - authorizes successfully, and …
Category: Web

I keep getting an error message in R while using twitteR

here is what I am doing: tweets=searchTwitter("walmart",n=3000, lang="en",since="2021-01-08",until="2021-01-10") And this is my error message: Warning message: In doRppAPICall("search/tweets", n, params = params, retryOnRateLimit = retryOnRateLimit, : 3000 tweets were requested but the API can only return 0 Any help would be appreciated.
Topic: twitter api r
Category: Data Science

How to disable inline css styles generated by Gutenberg editor?

I've got Genesis-blocks plugin installed (it got updated from Atomic blocks). I am using blocks and resuable blocks to create pages. The problem I am facing is, most of these blocks inject their own inline styling, e.g. button block creates an anchor tag, but it gives inline styling for background-color and text-color as well. Doing my own research I found that the default appearance of these blocks can be edited with javascript api, but the docs don't tell which javascript …
Category: Web

Pull in posts using post meta for REST API

So I wasn't able to find much detail about this, so I wanted to ask the community to see if I can get an answer. So let's say that I have the following: $this->global_endpoint = 'https://example.com/wp-json/global/v1/posts` which is the REST API endpoint for pulling in posts for WordPress. Then I am calling wp_remote_request such as this: $response = wp_remote_request(add_query_arg( [ 'page' => 1, 'per_page' => 3, 'post_status' => 'publish', ], $this->global_endpoint)); Does anyone know if it's possible to get a …
Category: Web

How to set a template with wp_insert_post

I'm trying to set my template to the Elementor Canvas when using wp_insert_post but it isn't working. It is creating the new page fine but not using the canvas. What am I doing wrong? { "action": "create_post", "post_author": "<authorID>", "post_content": "<post content>", "post_title": "Leave us a Review", "post_status": "publish", "post_type": "page", "comment_status": "closed", "post_name": "<post-name>", "page_template": "elementor_canvas" }
Category: Web

Twitter API Scraping Problem with Orange

I am trying to scrape tweets with the Twitter widget. However, when I try to connect Orange to my Twitter APP, it asks for a bearer token. After I put the bearer token, it shows up API error... I don't understand what is going on here.
Category: Data Science

WP Multisite - Additional subdomain on the site for API purposes

We have WP multisite network with WooCoomerce shops. All the network is served through Cloudflare CDN. Our ERP is accessing WooCommerce API of each website in the WP network. Since there so many, calls we are getting 503 from Cloudflare. It's not a server problem. It's a problem of too many requests to Cloudflare. So what I would like to have is a separated subdomain (example: api.domain.com) for each domain in the network. That subdomain will not be proxied thru …
Category: Web

Working Around rest_forbidden_context

I am trying to request page content, but the raw page content, calling this route: "/wp-json/wp/v2/pages/" + id + "?context=edit" In response to this I get: code: "rest_forbidden_context" data: {status: 401} message: "Sorry, you are not allowed to edit this post." Makes sense, guessing I just can't get the edit content unathenticated. However, it is unclear to me how I can retrieve the raw content of a post/page from the API. Potential Solutions I am struggling to find: Is there …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.