cristophergv
Forum Replies Created
-
Forum: Plugins
In reply to: [WP REST API (WP API)] How to write custom(my own) api in WP REST API Plugin?If possible, only the examples shown in internet is:
qod_remove_extra_data function ($ data, $ post, $ context) { // We only want to modify the 'view' context, for reading posts if ($ context! == 'view' || is_wp_error ($ data)) { return $ data; } // Here, we unset any data we do not want to see on the front end: unset ($data ['author']); unset ($data ['status']); // Continue unsetting whatever other fields you want return $ data; } add_filter ('json_prepare_post' 'qod remove extra_data', 12, 3);and right is:
qod_remove_extra_data function ($ data, $ post, $ context) { // We only want to modify the 'view' context, for reading posts if ($ context! == 'view' || is_wp_error ($ data)) { unset ( $data->data ['excerpt']); //Example unset ($data->data ['content']); //Example unset ($data->data ['name field to remove']) //or unset ($data->data ['name field to remove'] ['name subfield if you only want to delete the sub-field of field' ]) return $data; } } add_filter ('rest_prepare_post' 'qod_remove_extra_data', 12, 3);IMPORTANT, Is:
add_filter ('rest_prepare_post' 'qod_remove_extra_data', 12, 3);Not:
add_filter ('json_prepare_post' 'qod remove extra_data', 12, 3); //WRONGIf is Custom Post Type:
add_filter ('rest_prepare_{$post_type}' 'qod_remove_extra_data', 12, 3);EXAMPLE: Name post type = product;
add_filter ('rest_prepare_product' 'qod_remove_extra_data', 12, 3);With this code can remove the fields that you want the JSON. By using rest_prepare} _ {$ post_type decide that you eliminated every post_type fields, thus only affected the post_type you want and not all.
Forum: Plugins
In reply to: [JSON API] Request by a specific custom fieldsTo you dphiffer your plugin has helped me very much indeed. Thanks to him I have done many projects and lately over mobiles apps.
This is just my bit to your project.
Forum: Plugins
In reply to: [JSON API] Request by a specific custom fieldsHello rjme,
It is easy, when solicited query the system uses the parameters meta_key & meta_value as filters, namely:
If you created the custom field called special_field and its possible values 1 or 0 your query should look something like:
http://www.mywebsite.com/?json=get_posts&post_type=post&meta_key=special_field&meta_value=1 or = 0
according to whether you want to filter for 1 or 0.
If you have other custom field called my_special_field with possible values yes or not your query would look like:
http://www.mywebsite.com/?json=get_posts&post_type=post&meta_key=my_special_field&meta_value=yes
or
http://www.mywebsite.com/?json=get_posts&post_type=post&meta_key=my_special_field&meta_value=no
Is everything, with that return values can filter based on custom field.
Remember that you can use other parameters at WP_Query and seeing that functionality provides you.
https://codex.ww.wp.xz.cn/Class_Reference/WP_Query
Incidentally, the parameter post_type = post is optional, but it can be used in cases where for example you create a type of personalized post such artists, books, since that way you can get only results of such post as:
http://www.mywebsite.com/?json=get_posts&post_type=artista&meta_key=my_special_field&meta_value=no
or
http://www.mywebsite.com/?json=get_posts&post_type=libro&meta_key=author&meta_value=”armando “
Anything you say, have made mobile applications using as wordpress backend and json plugin-api, so I have some experience.
P.S. Sorry for the bad English but I speak Spanish and use google translate 🙂 hehe
/****
EN ESPAÑOL PARA MIS PAISANOS
*****/
Hola rjme,Es facil, cuando solicited una consulta al sistema, usa los parametros meta_key & meta_value como filtros, es decir:
Si el campo personalizado que creaste se llama special_field y tiene como posibles valores 1 o 0 tu consulta deberia ser algo asi:
http://www.mywebsite.com/?json=get_posts&post_type=post&meta_key=special_field&meta_value=1 or =0
segun quieras filtrar ya sea por 1 o por 0.
Si tienes otro campo personalizado que se llama my_special_field con posible valores yes or not tu consulta quedaria asi:
http://www.mywebsite.com/?json=get_posts&post_type=post&meta_key=my_special_field&meta_value=yes
or
http://www.mywebsite.com/?json=get_posts&post_type=post&meta_key=my_special_field&meta_value=no
Es todo, con eso puedes filtrar los valores devueltos basado en campo personalizado.
Recuerda que puedes usar otros parametros consultando WP_Query y viendo que funcionalidades te provee.
https://codex.ww.wp.xz.cn/Class_Reference/WP_Query
Por cierto, el parametro post_type=post es opcional, pero lo puedes usar en casos donde por ejemplo hayas creado un tipo de post personalizado por ejemplo Artistas, Libros, ya que de esa manera puedes obtener solo resultados de ese tipo de post por ejemplo:
http://www.mywebsite.com/?json=get_posts&post_type=artista&meta_key=my_special_field&meta_value=no
or
http://www.mywebsite.com/?json=get_posts&post_type=libro&meta_key=author&meta_value=”armando”
Cualquier cosa me dices, he realizado aplicaciones moviles usando como backend wordpress y el plugin json-api, asi que tengo algo de experiencia.
P.D. Lamento el mal ingles pero hablo español y use google translate jeje 🙂
Forum: Plugins
In reply to: [JSON API] How can i upload image through JSON API ?How?
Forum: Plugins
In reply to: [JSON API] Please don't let this AWESOME plugin die!Excellent dphiffer. You are the best.
Forum: Plugins
In reply to: [JSON API] get categoriesYes is posible, with: get_category_index
http://ww.wp.xz.cn/plugins/json-api/other_notes/#4.2.-Category-response-object
Another questions say me 🙂
Forum: Plugins
In reply to: [JSON API] Order by custom fieldWell, I answered myself.
To sort the posts in alphabetical order by custom field are passed as parameters to the query:
orderby = meta_value & meta_key = Custom field name & order = ASC or DESC. Example:http://127.0.0.1/wordpress/api/get_category_posts/?orderby=meta_value&meta_key=estado&order=ASC
or
http://127.0.0.1/wordpress/api/get_posts/?orderby=meta_value&meta_key=estado&order=ASC
And to get only posts that have some custom field values is adding:
meta_key = custom field name & meta_value = value to be searched. Example:http://127.0.0.1/wordpress/api/api/get_posts/?meta_key=estado&meta_value=colima
Good luck world.
Forum: Plugins
In reply to: [JSON API] Childrens categoryGreat, you’re great friend.
Forum: Plugins
In reply to: [JSON API] Childrens categoryExcelent, thanks my friend.
By the way, if anyone needs help with this problem or requirement and write in this post 🙂 help them how important it is to support everyone.
Forum: Plugins
In reply to: [JSON API] Childrens categoryHello dphiffer,
Thank you very much for responding. Rather, I wanted to get the girls category of particular category, no entries. Modify get_category_index function as a parameter so that we can pass and returned a category daughters and with that I could.
Your plugin is great, but I think that some other people have done some forks.
A doubt friend, if I want to create entries via JSON with the plugin, you need to add a username and password correct?. Got any example of how the code would have to be?.
Many thanks for your help 🙂
Have a happy day.
This error is because you don´t have active the option: Anything could register en in Admin Panel -> Settings -> General -> Members.
Active this option.
Have a nice day.
Good luck.