Im fairly new to WP development and am trying to create a plugin that generates a widget depending on the settings set in the custom post type. The widget is written in vue.js, and i would like to supply it with data from the WPDB (that i download and refresh using the plugin).
So a user can create a new custom post, set variables (example: URL of where the data is) and other settings inside that post, and then use the shortcode to display the widget.
I've created the plugin, read about custom post types and the REST API and created the frontend Widget.
My problem is this:
- How do i get Data from the DB to the frontend (vue.js)? Can i use the REST API for the WPDB?
- How can i use a custom post type to "feed" information into my widget? I assume i can just get the data from the WPDB about my custom post (storing the settings as part of the custom post), but that just brings me back to the first question.
- Do i use a "post template" to "inject" my widget, or is there something else for that?
Im fairly new to WP development and am trying to create a plugin that generates a widget depending on the settings set in the custom post type. The widget is written in vue.js, and i would like to supply it with data from the WPDB (that i download and refresh using the plugin).
So a user can create a new custom post, set variables (example: URL of where the data is) and other settings inside that post, and then use the shortcode to display the widget.
I've created the plugin, read about custom post types and the REST API and created the frontend Widget.
My problem is this:
- How do i get Data from the DB to the frontend (vue.js)? Can i use the REST API for the WPDB?
- How can i use a custom post type to "feed" information into my widget? I assume i can just get the data from the WPDB about my custom post (storing the settings as part of the custom post), but that just brings me back to the first question.
- Do i use a "post template" to "inject" my widget, or is there something else for that?
1 Answer
Reset to default 0
- How do i get Data from the DB to the frontend (vue.js)? Can i use the REST API for the WPDB?
The REST API works for this, or you could include the data in the HTML as JSON or a window variable
- How can i use a custom post type to "feed" information into my widget? I assume i can just get the data from the WPDB about my custom post (storing the settings as part of the custom post), but that just brings me back to the first question.
The REST API, this is pretty much the same question as above. Note that fetching posts in WP via WPDB
is highly unusual, and is commonly considered a code smell and bad practice. WP_Query
is a far superior/easier method
- Do i use a "post template" to "inject" my widget, or is there something else for that?
You could do that, but it would be easier to build a block or shortcode
Keep in mind, that retrieving the data and putting/embedding something in a post are on topic, but Vue.js is offtopic, you'll need to consult Vue.js communities on how it's used.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745351845a4623880.html
评论列表(0条)