query che visualizza dati dei meta box
-
Salve, ho usato questo generatore:
https://jeremyhixon.com/tool/wordpress-meta-box-generator-v2-beta/vorrei sapere come posso visualizzare il contenuto del meta box……
questo è il codice che doveva stampare anche il mio valore.. ma non stampa nulla.
ecco il codice:<?php get_header(); if(have_posts()) : while(have_posts()) : the_post(); ?> <h1><?php the_title(); ?></h1> <?php echo '<div class="entry-content">'; the_content(); echo get_post_meta( get_the_ID(), 'birth-day', true ); echo '</div>'; endwhile; endif; get_footer(); ?>
questo è il class .php
/** * Generated by the WordPress Meta Box Generator at http://goo.gl/8nwllb */ class Rational_Meta_Box { private $screens = array( 'staff', ); private $fields = array( array( 'id' => 'birth-day', 'label' => 'Birth Day', 'type' => 'date', ), ); /** * Class construct method. Adds actions to their respective WordPress hooks. */ public function __construct() { add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_action( 'save_post', array( $this, 'save_post' ) ); } /** * Hooks into WordPress' add_meta_boxes function. * Goes through screens (post types) and adds the meta box. */ public function add_meta_boxes() { foreach ( $this->screens as $screen ) { add_meta_box( 'extra-info', __( 'Extra info', 'marmoecolori' ), array( $this, 'add_meta_box_callback' ), $screen, 'advanced', 'default' ); } } /** * Generates the HTML for the meta box * * @param object $post WordPress post object */ public function add_meta_box_callback( $post ) { wp_nonce_field( 'extra_info_data', 'extra_info_nonce' ); echo 'Staff Extra information'; $this->generate_fields( $post ); } /** * Generates the field's HTML for the meta box. */ public function generate_fields( $post ) { $output = ''; foreach ( $this->fields as $field ) { $label = '<label for="' . $field['id'] . '">' . $field['label'] . '</label>'; $db_value = get_post_meta( $post->ID, 'extra_info_' . $field['id'], true ); switch ( $field['type'] ) { default: $input = sprintf( '<input %s id="%s" name="%s" type="%s" value="%s">', $field['type'] !== 'color' ? 'class="regular-text"' : '', $field['id'], $field['id'], $field['type'], $db_value ); } $output .= $this->row_format( $label, $input ); } echo '<table class="form-table"><tbody>' . $output . '</tbody></table>'; } /** * Generates the HTML for table rows. */ public function row_format( $label, $input ) { return sprintf( '<tr><th scope="row">%s</th><td>%s</td></tr>', $label, $input ); } /** * Hooks into WordPress' save_post function */ public function save_post( $post_id ) { if ( ! isset( $_POST['extra_info_nonce'] ) ) return $post_id; $nonce = $_POST['extra_info_nonce']; if ( !wp_verify_nonce( $nonce, 'extra_info_data' ) ) return $post_id; if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; foreach ( $this->fields as $field ) { if ( isset( $_POST[ $field['id'] ] ) ) { switch ( $field['type'] ) { case 'email': $_POST[ $field['id'] ] = sanitize_email( $_POST[ $field['id'] ] ); break; case 'text': $_POST[ $field['id'] ] = sanitize_text_field( $_POST[ $field['id'] ] ); break; } update_post_meta( $post_id, 'extra_info_' . $field['id'], $_POST[ $field['id'] ] ); } else if ( $field['type'] === 'checkbox' ) { update_post_meta( $post_id, 'extra_info_' . $field['id'], '0' ); } } } } new Rational_Meta_Box;
avete idea come faccio ad prendere il suo valore?
Perché questo funziona bene dopo ore di ricerche su google.
Mi potete aiutare? grazie mille e buona serata.
-
Questo topic è stato modificato 8 anni, 1 mese fa da
Luigi Amorfini.
-
Questo topic è stato modificato 8 anni, 1 mese fa da
-
Ciao @lamorfini,
lo sviluppatore del generatore è la tua miglior risorsa per capire come mai questo errore.
Qui invece la documentazione ufficiale sui meta box
https://codex.wordpress.org/Function_Reference/do_meta_boxes
https://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxesQuesto è quello che vuoi:
echo get_post_meta( get_the_ID(), 'extra_info_birth-day', true );
- Il topic ‘query che visualizza dati dei meta box’ è chiuso a nuove risposte.