2016-06-05 4 views
0

ich einige Details Beiträge hinzufügen müssen, so habe ich Seite zu ändern, hinzuzufügen/update Postwie benutzerdefinierte Post meta hinzufügen hinzufügen/aktualisieren alle Beiträge in Wordpress

aber ich weiß nicht, welche Maßnahmen i sollte

i zwei Auswahlboxen hinzufügen möchten, admin verwenden müssen zuerst Feld auswählen und dann wählen Sekunde zu

zum Beispiel Felder sind:

Liste Eins, Liste zwei, List Drei, List Vier

Und Sub Selects:

Liste One: Punkt eins, Punkt zwei, Punkt drei, Artikel Vier

Liste Two: Punkt eins, Punkt zwei, Punkt drei, Artikel Vier

pHP-Code:

// ============================== Add Province And City ... 
add_action('add_meta_boxes', 'selectIranProvinceCity'); 
add_action('save_post', 'iranProvinceCitySavePostData'); 
function selectIranProvinceCity(){ 

    // require_once('iran_province_city.php'); 

} 
function iranProvinceCitySavePostData(){ 
    // Save Province And City 
    $province = ''; 
    $city = ''; 
    if(isset($_POST['state'])) { 
     $province = $_POST['state']; 
    } 
    if(isset($_POST['city'])) { 
     $city = $_POST['city']; 
    } 
    $post_id = get_the_ID(); 
    if(!add_post_meta($post_id, 'province', $province, true)) { 
     update_post_meta($post_id, 'province', $province, true); 
    } 
    if(!add_post_meta($post_id, 'city', $city, true)) { 
     update_post_meta($post_id, 'city', $city, true); 
    } 
} 
// ============================== Add Province And City . 

Aber nein Wert auf Aktualisierung speichern, $post_id ist immer null

+1

goto Link http://stackoverflow.com/questions/35284060/create-custom-post-type-with-meta-boxes-title-name-and- Alter/35285603 # 35285603. und bekomme dein gewünschtes Bedürfnis – Coder

+0

wenn irgendein Problem Henne mir erzähle – Coder

+0

Ich bin Anfänger in PHP, also muss ich zwei Werte speichern, aber es speichere Liste oder einige Dinge mögen es, kannst du mir bitte helfen? – AndroSco

Antwort

5
add_action('init', 'update_all_templates_to_new'); 
function update_all_templates_to_new() 
{ 
    $args = array(
     'posts_per_page' => -1, 
     'post_type'  => 'product', 
     'suppress_filters' => true 
    ); 
    $posts_array = get_posts($args); 
    foreach($posts_array as $post_array) 
    { 
     update_post_meta($post_array->ID, '_use_new_product_template', '1'); 
    } 
} 
Verwandte Themen