0

I am new to Wordpress plugin development but not web development in general. I have a website whose functionality I am trying to port over to Wordpress for a client that needs it in a custom plugin and theme.

On my other (non-Wordpress) website, which is a shop page, I have no way of editing the shop items as a client, it is all hard coded into a complex JSON with nested arrays and objects that doesn't fit well into a MySQL.

An excerpt (it is from an Angular controller):

$scope.theBreadsList = [{
        category: 'Daily Breads',
        breads: [{
            text: 'Apple Streusel',
            category: 'Daily Breads',
            type: 'Apple Streusel',
            instance: 0,
            isDaily: true,
            price: 7.25,
            quantity: 0,
            days: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sunday"],
            daysNotAvailable: null,
            onMenu: true,
            canSlice: false,
            orderDates: [],
            theActualOrderDate: "",
            shipping: false,
            ingredients: ["White Flour", "Honey", "Water", "Butter", "Brown Sugar", "Eggs", "Applesauce", "Apples", "White Sugar", "Yeast", "Spices", "Vanilla", "Salt"]
        },


        {
            text: 'Honey Whole Wheat',
            category: 'Daily Breads',
            type: 'Honey Whole Wheat',
            instance: 0,
            isDaily: true,
            price: 5.65,
            quantity: 0,
            days: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sunday"],
            daysNotAvailable: null,
            onMenu: true,
            canSlice: true,
            orderDates: [],
            theActualOrderDate: "",
            shipping: false,
            ingredients: ["Organic Whole Wheat Flour","Filtered Water","Honey","Yeast","Salt"],
        },

Basically for the Wordpress plugin, I want the client to be able to enter in such categories and breads (or any other type of item) with all this associated data, to then be added to this format to be read by my Angular script.

Because I can't conceive of how to do this without storing it as JSON in the database itself (because it is too complex) I am stuck as to how I would have the client edit the data structure from within the plugin.

Sorry this is so vague, but I am hoping someone can help me conceptually with what to do here.

0

1 Answer 1

1

Just a pointer in the right direction:

You'll want a Custom Post Type bread.

Then you'll need a Custom Taxonomy for this CPT.

The rest will probably be post meta.

If the ingredients are just used like tags without a lot of data themselves you can make them a Custom Taxonomy as well. If they have separate URLs and content you'll probably want to implement them as CPTs and reference them via the IDs in post meta of the bread CPT.

When you create those CPTs and Taxonomies you can create them as public=false. That way they do not have their own URLs, but can be used to manage the data in the backend. Then you can use custom queries to build the JSON just the way you need it. Either the old fashioned way or using the REST API or just by outputting it inline in the page the angular app runs.

So basically you're only using WordPress to handle the Backend UI and then just build a JSON the way you need it for frontend.

3
  • That's an interesting suggestion, but in my Angular app I have everything loaded on a single page, which was my idea to emulate in Wordpress. That is,I'm not sure I would have custom post types because each bread is not its own post, but is loaded on one page and then fetched using Angular. Then again, maybe I need to investigate more what you are suggesting. :P Feb 23, 2016 at 16:55
  • I updated my answer, hope that helps.
    – kraftner
    Feb 23, 2016 at 17:02
  • Okay thanks, looks like a very interesting solution. So basically I am using the posts/taxonomy infrastructure in wordpress to generate the JSON I need? Feb 23, 2016 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.