Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature idea: Virtual fields #1288

Open
radeno opened this issue Nov 6, 2018 · 0 comments
Open

Feature idea: Virtual fields #1288

radeno opened this issue Nov 6, 2018 · 0 comments

Comments

@radeno
Copy link
Contributor

radeno commented Nov 6, 2018

Issue Overview

Based on this bug in #1268 (comment)

i get an idea about new field attribute property. Let name them just virtual which is boolean (default false) what allows you very interesting thing.

We are using some fields which add properties to post but that properties are not saved for post with defined fields, but in post which is addressed to.

Fox example in simple 1:N association. Yes, simple example. Something new post we associated with another post. It works fine for small datasets.

But when datasets is larger then is is very complicated to handle it.

Eg:

We have two post types. Type and Product. Forget to terms. Because we want custom post pages for TypeCategorys.

Then we define association attribute for Product

                [
                    'id'          => 'type_id',
                    'name'        => __('Type'),
                    'type'        => 'post',
                    'post_type'   => 'type',
                    'field_type'  => 'select_advanced',
                    'placeholder' => __('Types'),
                    'query_args'  => [
                        'post_status'    => 'publish',
                        'posts_per_page' => -1,
                        'order'          => 'ASC',
                        'orderby'        => 'title',
                    ],
                    'multiple' => true
                ]

Everything is fin, normalized and works. We have 200 products and 10 types.
Every product should have more than one type. And we want to add new type for better explanation of product.

Then we must open and edit every product which should have new product type. It is unfriendly, takes a lot time.

There is better solution. Reversing 1:N association but just in user interface not in data.
We could define field in Type post type:

                [
                    'id'          => '_assign_product_id',
                    'name'        => __('Assign Products'),
                    'type'        => 'post',
                    'post_type'   => 'product',
                    'field_type'  => 'select_advanced',
                    'placeholder' => __('Assign Product Id'),
                    'query_args'  => [
                        'post_status'    => 'publish',
                        'posts_per_page' => -1,
                        'order'          => 'ASC',
                        'orderby'        => 'title',
                    ],
                    'multiple' => true
                ]

And then we must add action save_post_type and make function which takes selected fields from saved field _assign_product_id, add them to another post and remove it from type post.

Is there any way how to process it in action when is everything validated and goes to save_post ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant