0

I need the child theme to use a 'modified' version of its parent custom post type and correspondent page template. Basically I would like to add 5 new metaboxes, change 2 existing labels, and include the new fields in the page template (code below).

***'Problem': The 'content module' of the page template, the page template itself, and Metaboxes of the custom post type are being defined/registered by the native plugin that the theme developer has also authored. As a very inexperienced aspiring 'developer', i was thinking to save the modified files in the child's directory, same ideas as, for example, header.php, and pray for it to overwrite...

Could you please advise???

    /**
 * Path: wp-content > plugins > theme plugin > includes > post types > class-realia-post-type-property.php 
 */

  $metaboxes[REALIA_PROPERTY_PREFIX . 'attributes'] = array(
        'id'                        => REALIA_PROPERTY_PREFIX . 'attributes',
        'title'                     => __( 'Attributes', 'realia' ),
        'object_types'              => array( 'property' ),
        'context'                   => 'normal',
        'priority'                  => 'high',
        'show_names'                => true,
        'fields'                    => array(
            array(
                'id'                => REALIA_PROPERTY_PREFIX . 'attributes_beds',
                'name'              => __( 'Beds', 'realia' ),
                'type'              => 'text',
            ),
            array(
                'id'                => REALIA_PROPERTY_PREFIX . 'attributes_baths',
                'name'              => __( 'Baths', 'realia' ),
                'type'              => 'text',
            ),
            array(
                'id'                => REALIA_PROPERTY_PREFIX . 'attributes_garages',
                'name'              => __( 'Garages', 'realia' ),
                'type'              => 'text',
            ),
            array(
                'id'                => REALIA_PROPERTY_PREFIX . 'attributes_area',
                'name'              => __( 'Area', 'realia' ),
                'type'              => 'text',
                'description'       => __( 'In unit set in settings.', 'realia' ),
            ),
            array(
                    'id'                => REALIA_PROPERTY_PREFIX . 'attributes_NEWONE',
                    'name'              => __( 'NEWONE', 'realia' ),
                    'type'              => 'text',
            ),
            array(
                    'id'                => REALIA_PROPERTY_PREFIX . 'attributes_NEWONE2',
                    'name'              => __( 'NEWONE2', 'realia' ),
                    'type'              => 'text',
            ),       
        )
    );

And then, I would go to the page template and:

<div class="entry-content">
    <div class="property-overview">
        <dl>
            <?php $price = Realia_Price::get_property_price(); ?>
            <?php if ( ! empty( $price ) ) : ?>
                <dt><?php echo __( 'Price', 'realia' )?></dt><dd><?php echo wp_kses( $price, wp_kses_allowed_html( 'post' ) ); ?></dd>
            <?php endif; ?>

            <?php $id = get_post_meta( get_the_ID(), REALIA_PROPERTY_PREFIX . 'id', true ); ?>
            <?php if ( ! empty( $id ) ) : ?>
                <dt><?php echo __( 'ID', 'realia' ); ?></dt><dd><?php echo esc_attr( $id ); ?></dd>
            <?php endif; ?>

            <?php $area = get_post_meta( get_the_ID(), REALIA_PROPERTY_PREFIX . 'attributes_area', true ); ?>
            <?php if ( ! empty( $area ) ) : ?>
                <dt><?php echo __( 'Area', 'realia' ); ?></dt><dd><?php echo esc_attr( $area ); ?> <?php echo get_theme_mod( 'realia_measurement_area_unit', 'sqft' ); ?></dd>
            <?php endif; ?>

            <?php $baths = get_post_meta( get_the_ID(), REALIA_PROPERTY_PREFIX . 'attributes_baths', true ); ?>
            <?php if ( ! empty( $baths ) ) : ?>
                <dt><?php echo __( 'Baths', 'realia' ); ?></dt><dd><?php echo esc_attr( $baths ); ?></dd>
            <?php endif; ?>

            <?php $beds = get_post_meta( get_the_ID(), REALIA_PROPERTY_PREFIX . 'attributes_beds', true ); ?>
            <?php if ( ! empty( $beds ) ) : ?>
                <dt><?php echo __( 'Beds', 'realia' ); ?></dt><dd><?php echo esc_attr( $beds ); ?></dd>
            <?php endif; ?>

            ?php $NEWONE = get_post_meta( get_the_ID(), REALIA_PROPERTY_PREFIX . 'attributes_NEWONE', true ); ?>
            <?php if ( ! empty( $NEWONE ) ) : ?>
                <dt><?php echo __( 'NEWONE', 'realia' ); ?></dt><dd><?php echo esc_attr( $NEWONE ); ?></dd>
            <?php endif; ?>

             ?php $NEWONE2 = get_post_meta( get_the_ID(), REALIA_PROPERTY_PREFIX . 'attributes_NEWONE2', true ); ?>
            <?php if ( ! empty( $NEWONE2 ) ) : ?>
                <dt><?php echo __( 'NEWONE2', 'realia' ); ?></dt><dd><?php echo esc_attr( $NEWONE2 ); ?></dd>
            <?php endif; ?>

            <?php $garages = get_post_meta( get_the_ID(), REALIA_PROPERTY_PREFIX . 'attributes_garages', true ); ?>
            <?php if ( ! empty( $garages ) ) : ?>
                <dt><?php echo __( 'Garages', 'realia' ); ?></dt><dd><?php echo esc_attr( $garages ); ?></dd>
            <?php endif; ?>
        </dl>
    </div><!-- /.property-overview -->

1 Answer 1

1

It seems to me like this is just a regular addition to functions. Since you are asking, I think you may not be getting the result you are looking for. If this was my project, I would create a new plugin, install it into the regular plugin list so that it does not get overwritten anywhere and then add the new properties.

Create a file called realia-compatiblity.php or something like that.

Add something like this to the start of the file:

<?php
/*
  Plugin Name: Realia Child Theme Compatibility Plugin
  Description: This is so my custom stuff doesn't get overwritten when the themes and plugins upgrade. Do not remove.
  Version: 1.0
  Author: YOUR NAME HERE
  Author URI: YOUR SITE HERE
  License: LIST LICENSING INFO HERE
*/

// Add your new code here
$metaboxes[REALIA_PROPERTY_PREFIX . 'attributes'] = array(
    'id'                        => REALIA_PROPERTY_PREFIX . 'attributes',
    'title'                     => __( 'Attributes', 'realia' ),
    'object_types'              => array( 'property' ),
    'context'                   => 'normal',
    'priority'                  => 'high',
    'show_names'                => true,
    'fields'                    => array(
        array(
            'id'                => REALIA_PROPERTY_PREFIX . 'attributes_beds',
            'name'              => __( 'Beds', 'realia' ),
            'type'              => 'text',
        ),
        array(
            'id'                => REALIA_PROPERTY_PREFIX . 'attributes_baths',
            'name'              => __( 'Baths', 'realia' ),
            'type'              => 'text',
        ),
        array(
            'id'                => REALIA_PROPERTY_PREFIX . 'attributes_garages',
            'name'              => __( 'Garages', 'realia' ),
            'type'              => 'text',
        ),
        array(
            'id'                => REALIA_PROPERTY_PREFIX . 'attributes_area',
            'name'              => __( 'Area', 'realia' ),
            'type'              => 'text',
            'description'       => __( 'In unit set in settings.', 'realia' ),
        ),
        array(
                'id'                => REALIA_PROPERTY_PREFIX . 'attributes_NEWONE',
                'name'              => __( 'NEWONE', 'realia' ),
                'type'              => 'text',
        ),
        array(
                'id'                => REALIA_PROPERTY_PREFIX . 'attributes_NEWONE2',
                'name'              => __( 'NEWONE2', 'realia' ),
                'type'              => 'text',
        ),       
    )
);

?>

And then your child theme information should be usable with your new child theme plugin.

Although, there seems to be some commands missing. I don't see any Hooks here to hook into an action, or any kind of registration for any custom post types. These would look something like this:

function custom_post_type() {
  // Some kind of labels
  // Some kind of arguments
  // a call to register_post_type();
};
// Hook into the 'init' action
add_action('init', 'custom_post_type', 0);

I am fairly new to all this as well and I could be missing something, however, it seems you may need to add a bit more than that what you have shared with us.

If what you were doing before wasn't working, perhaps this will. The code in the page template would likely remain the same.

I found this page to have a lot of useful information about custom post types in general http://www.smashingmagazine.com/2012/11/08/complete-guide-custom-post-types/

I hope this answer at least helps a bit! Good luck.

EDIT: I ran across this question initially thinking it was a custom post kind of question. I then went off to do research about a question I had about my own theme adjustments when I realised the stuff I was looking for was echoed here in this question. I reread your question and I saw you are looking for solutions to both the custom post and the custom metaboxes. Since the information is supposed to be added to the functions.php file as well, it is possible my plugin method would also work (untested!) for this metabox question. I found some information here that could illuminate things for you: http://www.creativebloq.com/wordpress/user-friendly-custom-fields-meta-boxes-wordpress-5113004

I hope that now there is enough here to help find the solutions!

3
  • Thank you very much niaskwalk! The plugin idea, unfortunately, didn't work but the resources you provided are great!!! I might be able to solve it today, I hope... Once again thank you!!!
    – VA-YVR
    Jun 22, 2015 at 16:52
  • @VA-YVR Glad my resources are helpful! It is just too bad the plugin doesn't work :-P I would be interested in the solution, so I hope you post it as an answer here! Jun 22, 2015 at 19:53
  • Sorry, I forgot to share the solution... I used cmb2 plugin github.com/WebDevStudios/CMB2 (really cool BTW) and then added a new metabox via child's theme functions.php. It worked beautifully... I hope it helps you too. Take a look at CMB2, it is really powerful. Cheers and once again thanks for your help.
    – VA-YVR
    Jul 8, 2015 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.