How to insert multiple images into a single post within a CPT?

Asked

Viewed 551 times

-1

I created a Custom Post Type to publish several images together.

--->>> title <<---
--->>> highlighted/default image <<<---
---->text<---
--->>images<<---
--->>images<<---
.....

The first three sections (title, highlighted image and text) are the basics. It’s ready.

Now, how can I add multiple images into this single CPT?

I thought of using Metabox and add the image url. However, adding url per url is not intuitive at all and gives much more work to the user, whether lay or advanced. Also, the amount of images will vary can be 1, can be 5, can be 10 and so on.

How can I add multiple images within a single post in a CPT?

Dashboard would look like this:

--->>> title <<---
--->>> text/content<<<---
--->>> highlighted image<<<---
--->>add images<<---

How can I do it? Whether by plugin or on hand same.

  • This problem is very complex. You can solve through repeatable metaboxes. Take a look at this here https://gist.github.com/helen/1593065

1 answer

0

Zkk,

the option considering the use of plugins is quite simple and easy to be implemented. There are numerous plugin alternatives available that offer a specific field type with the feature of being repeatable, which is exactly what you search for.

I will present some steps that intend to cover in a generic way the steps, regardless of the plugin chosen:

1) Choose a plugin that works with custom fields and that has the functionality of repeateable Fields (or loop). Search the Wordpress plugins directory, or use that comparative list which already lists several options.

Important: make a choice based on those who offer the resource repeateable Fields - which is a feature pointed out in the table.

2) After installing the plugin, the next step will be to create a custom field (or a group of fields, depending on the plugin you choose) of type IMAGE that is repeatable (or else a repeatable group that inside has an image field that can therefore be repeated).

3) Define in the filters of that field/group that they should be available only in your specific CPT.

4) Now implement your code. Each plugin uses a different function to return the recorded data with the custom fields, so see the documentation of the alternative you chose. In php, you will probably get an array of all the images, and then just run a foreach to print each of the available images.

Good luck!

Note: I have chosen not to specify a specific plugin to make this free of commercial interests, as many of them are available in free or paid versions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.