Comments (12)
I second this. The way it is setup now, using a related field means there always is a value.
It would be much more useful if there would be a blank option.
from magic-fields-2.
Hi carst,
I have edited the code for this field myself if you are interested. Just take this code and paste it into your magic fields directory/fields_type/related_type_field/related_type_field.php
description = __("This field allows to do relations with other post type",$mf_domain); } public function _options(){ global $mf_domain; ``` $posttypes = $this->mf_get_post_types(); $select = array(); foreach($posttypes as $k => $v){ $select[$k] = $v->label; } $data = array( 'option' => array( 'post_type' => array( 'type' => 'select', 'id' => 'post_type', 'label' => __('Related Type Panel (Post type)',$mf_domain), 'name' => 'mf_field[option][post_type]', 'default' => '', 'options' => $select, 'add_empty' => false, 'description' => '', 'value' => '', 'div_class' => '', 'class' => '' ), 'field_order' => array( 'type' => 'select', 'id' => 'field_order', 'label' => __('Field for order of Related type',$mf_domain), 'name' => 'mf_field[option][field_order]', 'default' => '', 'options' => array('id' => 'ID','title' =>'Title'), 'add_empty' => false, 'description' => '', 'value' => '', 'div_class' => '', 'class' => '' ), 'order' => array( 'type' => 'select', 'id' => 'order', 'label' => __('Order of Related type',$mf_domain), 'name' => 'mf_field[option][order]', 'default' => '', 'options' => array('asc' => 'ASC','desc' =>'DESC'), 'add_empty' => false, 'description' => '', 'value' => '', 'div_class' => '', 'class' => '' ), 'notype' => array( 'type' => 'text', 'id' => 'notype', 'label' => __('Default option (when no related type has been set)',$mf_domain), 'name' => 'mf_field[option][notype]', 'default' => '', 'options' => '', 'add_empty' => false, 'description' => '', 'value' => '', 'div_class' => '', 'class' => '' ) ) ); return $data; ``` } public function display_field( $field, $group_index = 1, $field_index = 1 ) { $output = ''; ``` $type = $field['options']->post_type; $order = $field['options']->order; $field_order = $field['options']->field_order; $notype = $field['options']->notype; $options = get_posts( sprintf("post_type=%s&numberposts=-1&order=%s&orderby=%s",$type,$order,$field_order) ); $output = 'It is really easy to customize fields in this version. It's quite brilliant really.
Eivind
from magic-fields-2.
Ignore all the weird stuff github does to my code. Just take out all that's between
from magic-fields-2.
Hey thanks! In the meantime I worked around the problem by just adding an option with a zero value and a type of '(none)'.
What you're doing does make more sense however, being able to choose a name for the empty type.
from magic-fields-2.
Hi Carst,
How exactly do you add an option to a related types field? I can't see that being possible anywhere. Care to explain?
Thanks
from magic-fields-2.
Hi Eivind, well exactly like you did it, by writing:
// adds an empty value $output .= sprintf('<option value="0">(none)</option>');
from magic-fields-2.
Oh, you did it with code as well then. That clarifies it.
Cheers.
E
from magic-fields-2.
Done.
Thank you @EivindFS and @carst :-)
@EivindFS the next time to you want to share some code with us can you use gist (https://gist.github.com/) ? thanks
from magic-fields-2.
Also the same issue with a Dropdown Field
from magic-fields-2.
IMHO is not necessary add a "None" option for Dropdown field because in that field you set the options by hand and you can set there the "None" value
from magic-fields-2.
Therefore that field always will be set, not empty. And "Required" option will not work correctly, and I will have to do some code to display nothing instead "None".
from magic-fields-2.
Yeah, you are right.
I'm going to work on this.
from magic-fields-2.
Related Issues (20)
- Url convert to relative url HOT 16
- display or not :) `? HOT 1
- Image Issues (both Image Media and Image Upload)
- Issue in required type of custom field "File" HOT 1
- Error
- Custom fields looks empty HOT 1
- Causing HTTP ERROR 500 on wp-admin HOT 1
- Plugin version in plugin folder name it's bad distribution approach
- Browser alert on every post saving
- Recoverable fatal error HOT 4
- When performing a full site export mappings do not persist
- Image from media not attaching to post
- Webshell Threat Found
- Problem with MF v2.3.3.1 and S3offload HOT 1
- Is this project active?
- plugin conflict
- Magic Fields data is not being saved HOT 1
- Date Picker not working with Wordpress 5.5 Update HOT 2
- Broken after Wordpress 5.4.4 HOT 2
- Estou postando ele salva mais não exibe nada no site
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magic-fields-2.