google-code-export / wordpress-custom-content-type-manager

Automatically exported from code.google.com/p/wordpress-custom-content-type-manager
2 stars 1 forks source link

Multiselect custom field is not fetching data from database #465

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Problem :Multiselect custom field is not fetching data from database, however 
static  options are displayed.

Solution: fields/multiselect.php -> public function 
get_edit_field_instance($current_value) 

//insert this code before line :$opt_cnt = count($this->options);

        if ($this->is_sql) {
            if (empty($this->alternate_input)) {
                return __('Alternate input must not be empty if SQL box is checked.', CCTM_TXTDOMAIN);
            }
            else {
                global $wpdb;
                global $table_prefix;
                $wpdb->hide_errors();
                $query = CCTM::parse($this->alternate_input, array('table_prefix'=>$table_prefix));
                //return $query;
                $results = $wpdb->get_results($query, ARRAY_N);
                if ($wpdb->last_error) {
                    return $wpdb->last_error;
                }
                $options = array();
                $values = array();
                foreach ($results as $r_i => $r) {
                    $options[$r_i] = $r[0];
                    if (isset($r[1])) {
                        $values[$r_i] = $r[1];
                    }
                    else {
                        $values[$r_i] = $r[0];
                    }
                }
                $this->set_prop('options', $options);
                $this->set_prop('values', $values);
            }
        }
        // Bulk input
        elseif (!$this->is_sql && !empty($this->alternate_input)) {
            $options = array();
            $values = array();
            $mixed = explode("\n",$this->alternate_input);
            foreach($mixed as $m_i => $m) {
                $line = explode('||',$m);
                $options[$m_i] = trim($line[0]);
                if (isset($line[1])) {
                    $values[$m_i] = trim($line[1]);
                }
                else {
                    $values[$m_i] = trim($line[0]);
                }
            }
            $this->set_prop('options', $options);
            $this->set_prop('values', $values);         
        }

Original issue reported on code.google.com by ever...@fireproofsocks.com on 4 Mar 2013 at 1:40

GoogleCodeExporter commented 9 years ago

Original comment by ever...@fireproofsocks.com on 6 Mar 2013 at 8:20

GoogleCodeExporter commented 9 years ago
This is not working and I am facing error like this 

You have an error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near 

Original comment by kushtrip...@gmail.com on 25 Jun 2013 at 6:02

GoogleCodeExporter commented 9 years ago
Sounds like you are trying to use an invalid MySQL query.  Paste your query 
into phpMyAdmin or into a MySQL command line prompt to verify that it is 
working.  Nothing in your message here leads me to believe that there is a 
problem with the CCTM.

Original comment by ever...@fireproofsocks.com on 25 Jun 2013 at 6:05