Create post using meta fields like "rehub_offer_product_coupon"

Open
REHub - Price Comparison, Affiliate Marketing, Multi Vendor Store, Community Theme REHub - Price Comparison, Affiliate Marketing, Multi Vendor Store, Community Theme October 27, 2021
Login to reply
Eduardo Ruiz Peña
2 years ago

That is a good idea and will help others like me. Now I can use all fields with my scripts :)


Congrats for your theme, is really amazing

Igor Sunz Support Agent
2 years ago

I think we can do better. I see growing number of users who use rest api. I think we will enable all default custom fields for posts directly in core of theme for rest api

Eduardo Ruiz Peña
2 years ago

Thank you very much for your help!, that was exactly my problem.

Solved now

Igor Sunz Support Agent
2 years ago

Rest api doesn’t include custom fields by default. They must be registered
in api first with register_meta

https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/


Ср, 27 окт. 2021 г. в 10:15, Sizam Support Help Desk <
sizamtheme+80YPnQm60ngDjB97XyKd@mail.support-hub.io>:

Eduardo Ruiz Peña
2 years ago



Hi!

I’m trying to add a coupon with API at the moment of create a post but the meta field is empty. I can create a post correctly using REST API but, I can only fill normal fields, not the one created by your theme.

I have installed a plugin called "REST API Custom Fields" which allows me to show meta fields in API REST calls, but, I can only read but not fill in the moment I create the post.

My Python code:

##############


import requests
import json
import base64

url = "https://xxxxxxxx.com/wp-json/wp/v2"

user = "user"
password = "applicationpass"

credentials = user + ':' + password

token = base64.b64encode(credentials.encode())

header = {'Authorization': 'Basic ' + token.decode('utf-8')}

# Just an image upload
media = {
    'file': open('imagen.jpg', 'rb'),
    'caption': 'First API Image',
    'description': 'First API Image'
}

image = requests.post(url + '/media', headers=header, files=media)
imageURL = str(json.loads(image.content)['source_url'])
imageID = str(json.loads(image.content)['id'])

meta = {
        "rehub_offer_product_coupon": "CUPONAPI",

       "other_meta_fields": "value"
}


post = {
    "date": "2021-10-22T08:32:00",
    "title": "Test post",
    "content": "test content with image id " + imageID + " and image URL " + imageURL,
    "status": "publish",
    "meta": meta,
    "featured_media": imageID
}

responce = requests.post(url + '/posts' , headers=header, json=post)

print(responce)
print(responce.json())

#####################

Is there anything I missing to be able to create post with all fields filled?


Let me know if you need credentials or my problem can be solved without access to site.


Thanks!

Additional Info

Link on page with issue: #