• What I’m trying to do is for a dual-language website. This particular language, Papiamento, isn’t supported by WordPress. Therefore, the client had to create two separate pages, in English and Pap. What I did was to code it like that to display English or Pap menu for each page.

    Like this, in header.php:

    ` <?php

    if( is_page( array(‘salon-and-spa-pap’, ‘tocante-nos’, ‘testimonio’, ‘tuma-contacto-cu-nos’, ‘galeria’, ‘tratamentonan-di-masahe’, ‘tratamentonan-spa-di-curpa’, ‘servicionan-di-boda’, ‘tratamentonan-spa-di-cara’, ‘wowo-lip-nek’, ‘cuido-di-man’, ‘tratamento-di-huna’, ‘tratamento-di-huna-di-pia’, ‘cuido-di-pia’, ‘salon-p’, ‘spa-etiquette-pap’, ‘wax-p’, ‘reserva-un-tratamento’)) ) {
    wp_nav_menu(array( ‘theme_location’ => ‘menu_top_pap’ ) );
    } else {
    wp_nav_menu(array( ‘theme_location’ => ‘secondary-menu’ ) );
    }

    ?>`

    However, the problem is that the client will have to keep going back to header.php to add another page slug every time she create a new page. Therefore, I created a Metabox plugin for that. I made a Metabox checkbox so that everytime a page is intended for Papiamento language, the client can just check the box and either the page id or slug will be added to the code above.

    I found another question (https://wordpress.stackexchange.com/questions/71043/listing-pages-with-checkboxes-in-a-metabox-and-saving-them) that might be similar to what I was looking for but it didn’t work for me.

    Here’s my metabox function based on this article (https://themefoundation.com/wordpress-meta-boxes-guide/).

    `<?php
    function prfx_custom_meta() {
    add_meta_box( ‘prfx_meta’, __( ‘Papiamento Page Box’, ‘prfx-textdomain’ ), ‘prfx_meta_callback’, ‘page’, ‘normal’, ‘low’ );
    }
    add_action( ‘add_meta_boxes’, ‘prfx_custom_meta’ );

    function prfx_meta_callback( $post ) {
    wp_nonce_field( basename( __FILE__ ), ‘prfx_nonce’ );
    $prfx_stored_meta = get_post_meta( $post->ID );
    $checkfield = maybe_unserialize( get_post_meta($post->ID, “checkfield”, true) );
    ?>

    <p>
    <span class=”prfx-row-title”><?php _e( ‘Pap Box’, ‘prfx-textdomain’ )?></span>
    <div class=”prfx-row-content”>
    <label for=”meta-checkbox”>
    <input type=”checkbox” name=”meta-checkbox” id=”meta-checkbox” value=”yes” <?php if ( isset ( $prfx_stored_meta[‘meta-checkbox’] ) ) checked( $prfx_stored_meta[‘meta-checkbox’][0], ‘yes’ ); ?> />
    <?php _e( ‘Check if this page is Papiamento’, ‘prfx-textdomain’ )?>
    </label>

    </div>
    </p>
    <?php
    }

    /**
    * Saves the custom meta input
    */
    function prfx_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[ ‘prfx_nonce’ ] ) && wp_verify_nonce( $_POST[ ‘prfx_nonce’ ], basename( __FILE__ ) ) ) ? ‘true’ : ‘false’;

    // Exits script depending on save status
    if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
    return;
    }

    // Checks for input and sanitizes/saves if needed

    // Checks for input and saves
    if( isset( $_POST[ ‘meta-checkbox’ ] ) ) {
    update_post_meta( $post_id, ‘meta-checkbox’, ‘yes’ );
    } else {
    update_post_meta( $post_id, ‘meta-checkbox’, ” );
    }

    }
    add_action( ‘save_post’, ‘prfx_meta_save’ );`

    Therefore, I’ve been trying to add pages to header.php. Help!!!

  • The topic ‘How to use Metabox checkbox to add page ids in array?’ is closed to new replies.