Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1048585

    I use the function below to add a metabox to posts, which word fine.
    I want this box in enfold portfolio items too, but can´t figure out how to do.

    function prfx_custom_meta() {
        add_meta_box( 'prfx_meta', __( 'Featured Post Startseite', 'prfx-textdomain' ), 'prfx_meta_callback', $screen = array("post"));
    }
    add_action( 'add_meta_boxes', 'prfx_custom_meta' );
    
    /**
     * Outputs the content of the meta box
     */
    function prfx_meta_callback( $post ) {
        wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' );
        $prfx_stored_meta = get_post_meta( $post->ID );
        ?>
    
     <p>
        <span class="prfx-row-title"><?php _e( 'Post in Homepage Karusell', 'prfx-textdomain' )?></span>
        <div class="prfx-row-content">
            <label for="homepage">
                <input type="checkbox" name="homepage" id="homepage" value="1" <?php if ( isset ( $prfx_stored_meta['homepage'] ) ) checked( $prfx_stored_meta['homepage'][0], '1' ); ?> />
                <?php _e( 'anzeigen', 'prfx-textdomain' )?>
            </label>
    
        </div>
    </p>
    <p>
        <span class="prfx-row-title"><?php _e( 'Sortierung', 'prfx-textdomain' )?></span>
        <div class="prfx-row-content">
            <label for="meta-radio-one">
                <input type="radio" name="sortierung" id="meta-radio-1" value="1" <?php if ( isset ( $prfx_stored_meta['sortierung'] ) ) checked( $prfx_stored_meta['sortierung'][0], '1' ); ?>>
                <?php _e( '1', 'prfx-textdomain' )?>
            </label>
            <label for="meta-radio-one">
                <input type="radio" name="sortierung" id="meta-radio-2" value="2" <?php if ( isset ( $prfx_stored_meta['sortierung'] ) ) checked( $prfx_stored_meta['sortierung'][0], '2' ); ?>>
                <?php _e( '2', 'prfx-textdomain' )?>
            </label>
            <label for="meta-radio-one">
                <input type="radio" name="sortierung" id="meta-radio-3" value="3" <?php if ( isset ( $prfx_stored_meta['sortierung'] ) ) checked( $prfx_stored_meta['sortierung'][0], '3' ); ?>>
                <?php _e( '3', 'prfx-textdomain' )?>
            </label>
            <label for="meta-radio-one">
                <input type="radio" name="sortierung" id="meta-radio-4" value="4" <?php if ( isset ( $prfx_stored_meta['sortierung'] ) ) checked( $prfx_stored_meta['sortierung'][0], '4' ); ?>>
                <?php _e( '4', 'prfx-textdomain' )?>
            </label>
            <label for="meta-radio-two">
                <input type="radio" name="sortierung" id="meta-radio-5" value="5" <?php if ( isset ( $prfx_stored_meta['sortierung'] ) ) checked( $prfx_stored_meta['sortierung'][0], '5' ); ?>>
                <?php _e( '5', '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 saves if needed
    if( isset( $_POST[ 'sortierung' ] ) ) {
        update_post_meta( $post_id, 'sortierung', $_POST[ 'sortierung' ] );
        
        
    }
       
    // Checks for input and saves
    if( isset( $_POST[ 'homepage' ] ) ) {
        update_post_meta( $post_id, 'homepage', '1' );
    } else {
        update_post_meta( $post_id, 'homepage', '' );
    }
     
    }
    
    add_action( 'save_post', 'prfx_meta_save' );
    #1049121

    Hey BingoEnvato,

    You would need to load the ALB from child theme and then load your metafields on ony section you need

    Best regards,
    Basilis

    #1136522

    Hi,

    it’s old topic, but changing post to portfolio works:

    
    function prfx_custom_meta() {
        add_meta_box( 'prfx_meta', __( 'Featured Post Startseite', 'prfx-textdomain' ), 'prfx_meta_callback', 'portfolio');
    }
    add_action( 'add_meta_boxes', 'prfx_custom_meta' );
    
    • This reply was modified 5 years, 2 months ago by fromcouch.
    #1136739

    Hi fromcouch,

    Thank you for your input :)

    Best regards,
    Victoria

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.