I am so new in WordPress plugin development. I have a plugin options page that contains one text field and one button. So when a url is given to the text field and stored with the button, using a shortcode that url appears where the shortcode is located. It is working so far. But what if I want to save multiple urls and produce multiple shortcodes ?!

I can produce an interface that has something like a [new URL] button that when clicked a new form generates with a unique value for the shortcode. But how can I add it to the database, instead of replacing it with the previous one.

Basically in this question, I am expecting some clue to understand how to approach to this case. There are many gallery plugins that work the same way. Can someone please explain the idea how to implement it?

Thanks in advance.

  • to create many objects, you can use a custom post type : codex.wordpress.org/Post_Types#Custom_Post_Types – mmm Dec 20 '17 at 22:57
  • 2
    Why not just use a shortcode attribute, eg. [my_shortcode url="http://example.com/"]? – Jacob Peattie Dec 20 '17 at 23:48
  • @JacobPeattie well it is not possible in my case because I am looking for a solution such as the photo gallery plugins, that there is always a button in the plugin settings page to create a new gallery and choose pics and etc then show the gallery with its giver Shortcode. – DannyBoy Dec 21 '17 at 3:40
  • Ass @mmm said, then you need a custom post type. – Jacob Peattie Dec 21 '17 at 3:45
  • 1
    That's all achievable with a custom post type and custom fields. If you don't want it to be a post type, there's no shortcut. You'd need custom database tables and APIs. You'd essentially be dealing with raw PHP/MySQL at that point. – Jacob Peattie Dec 21 '17 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.