Pagina 1 din 2 12 UltimulUltimul
Rezultate 1 la 10 din 18

Subiect: Notice: Undefined index

  1. #1
    Avatarul lui Maskatu
    Maskatu este deconectat Membru SeoPedia
    Reputatie:
    36
    Data înscrierii
    2nd July 2007
    Locaţie
    Ploiesti
    Posturi
    75
    Putere Rep
    36


    Implicit Notice: Undefined index

    Salutare!

    Am reusit sa fac sa functioneze un meta_box custom in wordpress dar am nevoie pe putin ajutor, pentru ca in modul wp_debug true, imi apar 3 erori, se pare toate din aceeasi cauza. De notat ca eroarea apare doar daca nimic nu este completat in custom field-urile respective.
    De exemplu, daca acest <?php echo $instructions; ?> nu afiseaza nimic pentru ca nimic nu a fost completat in acel camp, atunci apare acea eroare. Daca acel camp este completat (cu text in cazul meu), eroarea nu mai apare.

    Erorile suna asa:
    Cod:
    Notice: Undefined index: custom_meta_instructions in /.../single.php on line 11
    
    Notice: Undefined index: custom_meta_gamefile in /.../single.php on line 13
    Liniile respective sunt corespunzatoare urmatoarelor coduri:
    Cod:
    <?php
      $custom_meta = get_post_custom($post->ID);
      $instructions = $custom_meta['custom_meta_instructions'][0];
      $difficulty = $custom_meta['custom_meta_difficulty'][0];
      $gamefile = $custom_meta['custom_meta_gamefile'][0];
    ?>
    Functia corespunzatoare acestora este urmatoarea:

    Cod:
        $prefix = 'custom_meta_';
        $meta_box = array(
        'fields' => array(
       array(
        'name'    => 'Upload your swf game file:',
        'desc'    => 'Upload your swf game file using upload/insert media button, or paste your embed code. <br />*<small>Note that if you are using embed code, you should use the HTML tab instead of Visual. Anyway, sometimes you must play around with the dimension of the game, to display the proportional width and heigh.</small>',
        'id'      => $prefix . 'gamefile',
        'type'    => 'wysiwyg',
        'std' => '',
        'options' => array(
        'textarea_rows' => 3,
    ),
    ),
       array(
        'name' => 'Game Instructions:',
        'desc' => 'Instructions about how to play the game (key used to play, move, jump, etc.).',
        'id' => $prefix . 'instructions',
        'type'    => 'wysiwyg',
        'std' => '',
        'options' => array(
        'media_buttons' => false,
        'textarea_rows' => 3,
    
    ),
    ),
       array(
        'name' => 'Game Difficulty:',
        'id' => $prefix . 'difficulty',
        'type' => 'select',
        'options' => array('Very Easy', 'Easy', 'Medium', 'Hard', 'Very Hard' )
    
    ),
    )
    );
    
      function my_game_meta_add_box() {
        global $meta_box;
    
      }
      add_action('admin_menu', 'my_game_meta_add_box');
      function display_gamecode() {
        global $meta_box, $post;
        echo '<input type="hidden" name="flash_game_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
        echo '<table class="form-table">';
      foreach ($meta_box['fields'] as $field) {
        $meta = get_post_meta($post->ID, $field['id'], true);
        echo '<tr>',
        '<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
        '<td>';
        switch ($field['type']) {
      case 'wysiwyg':
        wp_editor( $meta ? $meta : $field['std'], $field['id'], isset( $field['options'] ) ? $field['options'] : array() );
        echo '<p>', $field['desc'], '</p>';
      break;
      case 'select':
        echo '<select name="', $field['id'], '" id="', $field['id'], '">';
      foreach ($field['options'] as $option) {
        echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>';
      }
        echo '</select>';
      break;
      }
        echo '<td>',
            '</tr>';
      }
        echo '</table>';
      }
      function my_game_meta_save_data($post_id) {
        global $meta_box;
    
     if( !isset( $_POST['flash_game_meta_box_nonce'] ) || !wp_verify_nonce($_POST['flash_game_meta_box_nonce'], basename(__FILE__))) {
        return $post_id;
      }
        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
      }
        if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
        return $post_id;
      }
      } elseif (!current_user_can('edit_post', $post_id)) {
        return $post_id;
      }
      foreach ($meta_box['fields'] as $field) {
        $old = get_post_meta($post_id, $field['id'], true);
        $new = $_POST[$field['id']];
        if ($new && $new != $old) {
        update_post_meta($post_id, $field['id'], $new);
      } elseif ('' == $new && $old) {
        delete_post_meta($post_id, $field['id'], $old);
      }
      }
      }
    Chiar am nevoie de ajutor pentru ca acele erori sa nu mai apara asa ca multumesc anticipat celui care ma poate ajuta!

  2. #2
    Avatarul lui -Rares-
    -Rares- este deconectat Ambasador
    Reputatie:
    53
    Data înscrierii
    14th May 2009
    Locaţie
    Bucuresti
    Vârstă
    40
    Posturi
    1.623
    Putere Rep
    53


    Implicit

    Inainte de a te folosi de acea valoare, trebuie facuta o verificare daca ea exista. Uite un exemplu care afiseaza boxul tau cu info doar daca cele 3 valori exista (daca vrei poti pune conditii individuale sau poti seta niste valori default in cazul in care valorile nu sunt setate):

    Cod PHP:
    <?php
    $custom_meta 
    get_post_custom($post->ID);

    if (
    $custom_meta['custom_meta_instructions'][0] && $custom_meta['custom_meta_difficulty'][0] &&   $custom_meta['custom_meta_gamefile'][0] ){

      
    $instructions $custom_meta['custom_meta_instructions'][0];
      
    $difficulty $custom_meta['custom_meta_difficulty'][0];
      
    $gamefile $custom_meta['custom_meta_gamefile'][0];

      echo 
    'aici afisezi boxul tau cu informatii';
    }
    ?>
    Ultima modificare făcută de -Rares-; 7th December 2012 la 10:15.
    Creștere putere, consum redus și optimizare software motor - servicii profesionale de chiptuning

  3. #3
    Avatarul lui Maskatu
    Maskatu este deconectat Membru SeoPedia
    Reputatie:
    36
    Data înscrierii
    2nd July 2007
    Locaţie
    Ploiesti
    Posturi
    75
    Putere Rep
    36


    Implicit

    Exact asta am nevoie: o verificare daca acea valoare exista. Multumesc pentru ajutor dar din pacate eroarea persista: Undefined index: custom_meta_instructions ...

  4. #4
    Avatarul lui -Rares-
    -Rares- este deconectat Ambasador
    Reputatie:
    53
    Data înscrierii
    14th May 2009
    Locaţie
    Bucuresti
    Vârstă
    40
    Posturi
    1.623
    Putere Rep
    53


    Implicit

    pai persista din cauza ca tu afizezi datele in alta parte. Trebuie sa pui acea conditie acolo udne afisezi datele
    Creștere putere, consum redus și optimizare software motor - servicii profesionale de chiptuning

  5. #5
    Avatarul lui Maskatu
    Maskatu este deconectat Membru SeoPedia
    Reputatie:
    36
    Data înscrierii
    2nd July 2007
    Locaţie
    Ploiesti
    Posturi
    75
    Putere Rep
    36


    Implicit

    Am incercat doar cu o singura valoare exact in locul unde trebuie afisat insa fara succes... Multumesc oricum.

  6. #6
    Avatarul lui inSecure
    inSecure este deconectat Membru SeoPedia
    Reputatie:
    39
    Data înscrierii
    2nd December 2007
    Posturi
    612
    Putere Rep
    39


    Implicit

    Cod PHP:
    if ($custom_meta['custom_meta_instructions'][0] && $custom_meta['custom_meta_difficulty'][0] &&   $custom_meta['custom_meta_gamefile'][0] ){ 

      
    $instructions $custom_meta['custom_meta_instructions'][0]; 
    Nu poti pune ceva de genul:
    Cod PHP:
    if (!isset($custom_meta['custom_meta_instructions'][0])){ 

      
    $instructions NULL

    Nu sunt programator PHP, dar ma gandesc ca poate ar merge ceva de genul.
    Hmm..ar merge o lada de bere

  7. #7
    Avatarul lui -Rares-
    -Rares- este deconectat Ambasador
    Reputatie:
    53
    Data înscrierii
    14th May 2009
    Locaţie
    Bucuresti
    Vârstă
    40
    Posturi
    1.623
    Putere Rep
    53


    1 out of 1 members found this post helpful.

    Implicit

    Ceva faci gresit. Daca nu rezolvi pana diseara te ajut eu dupa ora 19.

    Ca idee, iti recomand sa extragi valorile din custom fields astfel:

    Cod PHP:
    <?php echo get_custom_field('custom_meta_instructions'); ?>
    deci afisarea o faci asa:

    Cod PHP:
    <?php if (get_custom_field('custom_meta_instructions')) : ?>
        <div class="instructions"><?=get_custom_field('custom_meta_instructions');?></div>
    <? endif; ?>
    <?php 
    if (get_custom_field('difficulty')) : ?>
        <div class="difficulty"><?=get_custom_field('difficulty');?></div>
    <? endif; ?>
    Prin urmare renunti la blocul de cod <?php
    $custom_meta = get_post_custom($post->ID);
    $instructions = $custom_meta['custom_meta_instructions'][0];
    $difficulty = $custom_meta['custom_meta_difficulty'][0];
    $gamefile = $custom_meta['custom_meta_gamefile'][0];
    ?>
    Creștere putere, consum redus și optimizare software motor - servicii profesionale de chiptuning

  8. #8
    Avatarul lui Maskatu
    Maskatu este deconectat Membru SeoPedia
    Reputatie:
    36
    Data înscrierii
    2nd July 2007
    Locaţie
    Ploiesti
    Posturi
    75
    Putere Rep
    36


    Implicit

    Citat Postat în original de -Rares- Vezi Post
    Ceva faci gresit. Daca nu rezolvi pana diseara te ajut eu dupa ora 19.
    Ce sa spun, sunt super recunoscator! Ideea este ca si eu sunt putin ocupat acum (un mini-webmaster de un an juma` care m-a capiat!) si nu am avut timp sa studiez atent codurile. Ma eliberez intr-o ora dupa care revin si incerc sa expun corect codurile. Ca idee, sunt cam habarnist in privinta php-ului, asa ca orice ajutor e binevenit, sunt abia la inceput...
    Multumesc!

    --- Later Edit --- (ca mi-a fost lene sa apas "Edit")

    Citat Postat în original de inSecure Vezi Post
    [PHP]Nu sunt programator PHP, dar ma gandesc ca poate ar merge ceva de genul.
    Inca nu... Oricum multumesc pentru intentie

  9. #9
    Avatarul lui casperel
    casperel este deconectat Membru SeoPedia
    Reputatie:
    45
    Data înscrierii
    10th February 2007
    Locaţie
    Bucuresti
    Posturi
    838
    Putere Rep
    45


    2 out of 2 members found this post helpful.

    Implicit

    Cod PHP:
      $custom_meta get_post_custom($post->ID);
      
    $instructions = !empty($custom_meta['custom_meta_instructions'][0]) ? $custom_meta['custom_meta_instructions'][0] : NULL;
      
    $difficulty = !empty($custom_meta['custom_meta_difficulty'][0]) ? $custom_meta['custom_meta_difficulty'][0] : NULL;
      
    $gamefile = !empty($custom_meta['custom_meta_gamefile'][0]) ? $custom_meta['custom_meta_gamefile'][0] : NULL

  10. #10
    Avatarul lui Maskatu
    Maskatu este deconectat Membru SeoPedia
    Reputatie:
    36
    Data înscrierii
    2nd July 2007
    Locaţie
    Ploiesti
    Posturi
    75
    Putere Rep
    36


    Implicit

    Citat Postat în original de casperel Vezi Post
    Cod PHP:
      $custom_meta get_post_custom($post->ID);
      
    $instructions = !empty($custom_meta['custom_meta_instructions'][0]) ? $custom_meta['custom_meta_instructions'][0] : NULL;
      
    $difficulty = !empty($custom_meta['custom_meta_difficulty'][0]) ? $custom_meta['custom_meta_difficulty'][0] : NULL;
      
    $gamefile = !empty($custom_meta['custom_meta_gamefile'][0]) ? $custom_meta['custom_meta_gamefile'][0] : NULL
    Merge brici: fara erori, valorile se salveaza, nota 10!
    Multumesc man!

    --- Later Edit --- (ca mi-a fost lene sa apas "Edit")

    Citat Postat în original de -Rares- Vezi Post
    Ceva faci gresit. Daca nu rezolvi pana diseara te ajut eu dupa ora 19....
    Rares, am rezolvat aplicand sugestia de mai sus a lui @casperel.
    Multumesc mult oricum!

Pagina 1 din 2 12 UltimulUltimul

Informații subiect

Utilizatori care navighează în acest subiect

Momentan este/sunt 1 utilizator(i) care navighează în acest subiect. (0 membrii și 1 vizitatori)

Thread-uri Similare

  1. Notice of DMCA removal from Google Search
    De Bogdan Patru în forumul Subiecte pentru incepatori
    Răspunsuri: 3
    Ultimul Post: 15th August 2012, 10:43
  2. Notice of Suspected Hacking on http://www.root.tld
    De Andrei S în forumul Webmaster Tools
    Răspunsuri: 3
    Ultimul Post: 9th May 2011, 14:43
  3. index.php to /
    De gaby în forumul Server side
    Răspunsuri: 2
    Ultimul Post: 27th August 2010, 18:29
  4. Z-index
    De afac3rist în forumul Google
    Răspunsuri: 2
    Ultimul Post: 18th February 2009, 13:47
  5. CPanel-Index Manager E bine sa pun No index?
    De evolution în forumul Server side
    Răspunsuri: 4
    Ultimul Post: 8th July 2008, 20:17

Permisiuni postare

  • Nu puteţi posta subiecte noi.
  • Nu puteţi răspunde la subiecte
  • Nu puteţi adăuga ataşamente
  • Nu puteţi modifica posturile proprii
  •