mercredi 11 mai 2016

How do I display my meta box custom fields meta data on a page?

I have created a survey plugin, I made a custom post type that will act as a survey question, I have created options in a form of input field, I was able to save the metadata in the WordPress post database. How can I display or get the data? and output it on a page?

anyone knows how can I get the options data and insert in a radio button below the post title as the question.

here is the code I used to save the custom fields meta data

function survey_questions_meta_save( $post_id ) {
  // Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'survey_questions_nonce' ] ) && wp_verify_nonce( $_POST[ 'survey_questions_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
    return;
}
if ( isset( $_POST[ 'option1' ] ) ) {
  update_post_meta( $post_id, 'option1', sanitize_text_field( $_POST[ 'option1' ] ) );
}
if ( isset( $_POST[ 'option2' ] ) ) {
  update_post_meta( $post_id, 'option2', sanitize_text_field( $_POST[ 'option2' ] ) );
}
if ( isset( $_POST[ 'option3' ] ) ) {
  update_post_meta( $post_id, 'option3', sanitize_text_field( $_POST[ 'option3' ] ) );
}
if ( isset( $_POST[ 'option4' ] ) ) {
  update_post_meta( $post_id, 'option4', sanitize_text_field( $_POST[ 'option4' ] ) );
}
if ( isset( $_POST[ 'option5' ] ) ) {
  update_post_meta( $post_id, 'option5', sanitize_text_field( $_POST[ 'option5' ] ) );
}
}
add_action( 'save_post', 'survey_questions_meta_save' );



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire