There are arbitrary types of records, let's call them. Objects did download xml in Yandex format, but for some reason I can only add standard fields, such as title data meta content. How to organize the loading of additional fields? in which direction to poke?
So I add my extra fields on the page custom-single.php
<?php $contact_descr = get_post_meta($post->ID, 'contact_descr', true); ?> <?php if (empty($contact_descr)) { echo ""; } else { ?> <?php echo "<li>".$contact_descr."</li>"; } ?> So trying to load fields
1 variables.php files
<?php namespace best_import_namespace; // xml global $xml, $xml_content; if(file_exists($xml_file)){ $xml = simplexml_load_file($xml_file); $xml_content = file_get_contents($xml_file); }else{ $xml = null; $xml_content = null; } // others global $tags, $max_preview, $import_number, $post_types, $post_type, $main_tag, $default_action; $tags = array(); $max_preview = 1024; $import_number = intval(gpost('import-number')); $post_types = get_post_types(); $post_type = gpost('post-type', 'post'); $main_tag = gpost('main-tag', ''); $default_action = 'add'; // default fields global $default_fields; $default_fields = array( 'title' => array('name'=>'title', 'value'=>gpost('title'), 'type'=>'string', 'label'=>'Title'), 'content' => array('name'=>'content', 'value'=>gpost('content'), 'type'=>'string', 'label'=>'Content'), 'date' => array('name'=>'date', 'value'=>gpost('date'), 'type'=>'date', 'label'=>'Date'), 'contact_descr' => array('name'=>'contact_descr', 'value'=>gpost('ontact_descr'), 'type'=>'string', 'label'=>'contact_descr'), ); // taxonomies global $taxonomies, $taxonomies_objects; $taxonomies = array(); $taxonomies_objects = get_taxonomies(array(), 'objects'); foreach($taxonomies_objects as $taxonomy) if(in_array($post_type, $taxonomy->object_type)){ $value = gpost('taxonomies', array()); $value = isset($value[$taxonomy->name])?$value[$taxonomy->name]:''; $taxonomies[$taxonomy->name] = array( 'name' => $taxonomy->name, 'value' => $value, 'type' => 'string', 'label' => $taxonomy->label ); } // mapping global $mapping; $mapping = array(); $mapping_names = gpost('mapping_names', array()); $mapping_from = gpost('mapping_from', array());; $mapping_to = gpost('mapping_to', array()); $mapping_count = count($mapping_names); for($j=0; $j<$mapping_count; ++$j) $mapping[] = array( 'name' => $mapping_names[$j], 'from' => $mapping_from[$j], 'to' => $mapping_to[$j] ); // merge global $all_fields; $all_fields = array_merge($default_fields, $taxonomies); // input types global $input_types; $input_types = array( 'string' => 'String', 'int' => 'Integer', 'float' => 'Float', 'date' => 'Date', ); ?> data.php
<?php namespace best_import_namespace; echo '<h3>Data</h3>'; if($xml){ echo '<h4>Fill the form below to match appropriate attributes with the data.</h4>'; echo '<table class="form-table">'; echo '<tr><td><label for="bi-main-tag">Main tag</label></td><td><select name="main-tag" value="" id="bi-main-tag">'; foreach($tags as $tag=>$array)echo '<option name="import-number" value="'.$tag.'"'.($tag==$main_tag?' selected="selected"':'').'><'.$tag.'></option>'; echo '</select></td></tr>'; echo '<tr><td><label for="bi-type">Type</label></td><td><select name="post-type" id="bi-type">'; foreach($post_types as $type)echo '<option value="'.$type.'"'.($type==$post_type?' selected="selected"':'').'>'.$type.'</option>'; echo '</select></td></tr>'; echo '<tr><td><label for="bi-title">Title</label></td><td><input type="text" value="'.gpost('title').'" name="title" id="bi-title" class="suggest"></td></tr>'; echo '<tr><td><label for="bi-content">Content</label></td><td><textarea name="content" id="bi-content" class="suggest">'.gpost('content').'</textarea></td></tr>'; echo '<tr><td><label for="bi-date">Date</label></td><td><input type="text" value="'.gpost('date').'" name="date" id="bi-date" class="suggest"></td></tr>'; echo '<tr><td><label for="bi-date">Адрес</label></td><td><input type="text" value="'.gpost('extra[contact_descr]').'" name="extra[contact_descr]" id="bi-extra[contact_descr]" class="suggest"></td></tr>'; echo '</table>'; }else{ echo '<h4>You have not uploaded XML file yet.</h4>'; } ?>