Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter yiags987

    (@yiags987)

    Thank you very much for your answer ‘cubecolour’ – it started me on the right track and with the help of a few tutorials I got well under way! If anyone comes across this post they were:

    https://wptheming.com/2010/08/custom-metabox-for-post-type/

    https://code.tutsplus.com/tutorials/a-guide-to-wordpress-custom-post-types-creation-display-and-meta-boxes–wp-27645

    Seeing as you were so nice to help – I hoped you have time to help with the last part of my problem to get me finished?

    I have now created the plugin and it works really well. I have a new menu item called ‘bands’ for all my pages and the metaboxes in admin I require for the extra information.

    I have one or 2 small issues left – 1 which is really vexing me! As you will see in the code below – I have one section called “Festival Appearances” which has a field for the festival name & then then the date of the show. I want to make this field a REPEATABLE field so the user can click a “add another +” link and get a new meta box to enter a 2nd festival appearance.

    I have seen plenty of code to do it but am having a real hard time mixing it with what I have. Along the way I wouldn’t mind making the date field a ‘date picker’ rather than the standard text area if anyone know how?

    Any help would be greatly appreciated! Code below:

    // Registers the new post type and taxonomy
    
    function wpt_bands_posttype() {
    	register_post_type( 'bands',
    		array(
    			'labels' => array(
    				'name' => __( 'Bands' ),
    				'singular_name' => __( 'Band' ),
    				'add_new' => __( 'Add New Band' ),
    				'add_new_item' => __( 'Add New Band' ),
    				'edit_item' => __( 'Edit Band' ),
    				'new_item' => __( 'Add New Band' ),
    				'view_item' => __( 'View Band' ),
    				'search_items' => __( 'Search Band' ),
    				'not_found' => __( 'No bands found' ),
    				'not_found_in_trash' => __( 'No bands found in trash' )
    			),
    			'public' => true,
    			'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ),
    			'capability_type' => 'post',
    			'rewrite' => array("slug" => "bands"), // Permalinks format
    			'menu_position' => 5,
    			'menu_icon' => plugins_url( 'icon.png', __FILE__ ),
    			'register_meta_box_cb' => 'add_bands_metaboxes'
    		)
    	);
    }
    
    add_action( 'init', 'wpt_bands_posttype' );
    add_action( 'add_meta_boxes', 'add_bands_metaboxes' );
    
    // Add the Events Meta Boxes
    
    function add_bands_metaboxes() {
    	add_meta_box('wpt_bands_details', 'Band Details', 'wpt_bands_details', 'bands', 'normal', 'default');
    }
    
    // The Event Location Metabox
    
    function wpt_bands_details() {
    	global $post;
    
    	// Noncename needed to verify where the data originated
    	echo '<input type="hidden" name="bandsmeta_noncename" id="bandsmeta_noncename" value="' .
    	wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
    
    	// Get the location data if its already been entered
    	$video = get_post_meta($post->ID, '_video', true);
            $soundcloud = get_post_meta($post->ID, '_soundcloud', true);
    			$facebookLink = get_post_meta($post->ID, '_facebookLink', true);
    	$festivalname = get_post_meta($post->ID, '_festivalname', true);
    	$festivaldate = get_post_meta($post->ID, '_festivaldate', true);
    
    	// Echo out the field
            echo '<p><span style="font-weight: bold; font-size: 18px; color: #F00">Video URL:</span></p>';
    	 echo '<textarea id="texty" name="_video" class="widefat">' . esc_html( $video ) . '</textarea>';
            echo '<p><span style="font-weight: bold; font-size: 18px; color: #F00">SoundCloud Playlist URL</span></p>';
    	 echo '<textarea id="texty" name="_soundcloud" class="widefat">' . esc_html( $soundcloud ) . '</textarea>';
    		  echo '<p style="font-weight: bold; font-size: 18px; color: #F00">Facebook Link</p>';
    	 echo '<input type="url" name="_facebookLink" value="' . $facebookLink  . '" class="widefat" />';
    
    	   echo '<p style="font-weight: bold; font-size: 18px; color: #F00">Festival Appearances</p>';
    	 echo '
    	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><p>Festival Name </p><br/><input type="text" name="_whichfestone" value="' . $festivalname  . '" class="widefat" /></td>
        <td><p>Festival Date </p><br/><input type="text" name="_whichfesttwo" value="' . $festivaldate  . '" class="widefat" /></td>
      </tr>
    </table>
    	';
    
    	}
    
    // Save the Metabox Data
    
    function wpt_save_bands_meta($post_id, $post) {
    
    	// verify this came from the our screen and with proper authorization,
    	// because save_post can be triggered at other times
    	if ( !wp_verify_nonce( $_POST['bandsmeta_noncename'], plugin_basename(__FILE__) )) {
    	return $post->ID;
    	}
    
    	// Is the user allowed to edit the post or page?
    	if ( !current_user_can( 'edit_post', $post->ID ))
    		return $post->ID;
    
    	// OK, we're authenticated: we need to find and save the data
    	// We'll put it into an array to make it easier to loop though.
    
    	$bands_meta['_details'] = $_POST['_details'];
    	$bands_meta['_video'] = $_POST['_video'];
        $bands_meta['_soundcloud'] = $_POST['_soundcloud'];
    	$bands_meta['_festivalname'] = $_POST['_festivalname'];
    	$bands_meta['_festivaldate'] = $_POST['_festivaldate'];
    
    	// Add values of $events_meta as custom fields
    
    	foreach ($bands_meta as $key => $value) { // Cycle through the $events_meta array!
    		if( $post->post_type == 'revision' ) return; // Don't store custom data twice
    		$value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
    		if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
    			update_post_meta($post->ID, $key, $value);
    		} else { // If the custom field doesn't have a value
    			add_post_meta($post->ID, $key, $value);
    		}
    		if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
    	}
    
    }
    
    add_action('save_post', 'wpt_save_bands_meta', 1, 2); // save the custom fields
    
    // My template force code
    
    function include_template_function( $template_path ) {
        if ( get_post_type() == 'bands' ) {
            if ( is_single() ) {
                // checks if the file exists in the theme first,
                // otherwise serve the file from the plugin
                if ( $theme_file = locate_template( array ( 'plugin-page.php' ) ) ) {
                    $template_path = $theme_file;
                } else {
                    $template_path = plugin_dir_path( __FILE__ ) . '/plugin-page.php';
                }
            }
        }
        return $template_path;
    }
    
    // My template force call
    add_filter( 'template_include', 'include_template_function', 1 );
    ?>
    Thread Starter yiags987

    (@yiags987)

    My System Status log is as follows:

    WC Version: 	2.0.20
    WC Database Version: 	2.0.20
    WP Version: 	WP 3.8
    Web Server Info: 	Apache
    PHP Version: 	5.4.23
    MySQL Version: 	5.1.72-log
    WP Memory Limit: 	64 MB
    WP Debug Mode: 	No
    WP Max Upload Size: 	8 MB
    PHP Post Max Size: 	8 MB
    PHP Time Limit: 	50000
    WC Logging: 	Log directory is writable.
    Default Timezone: 	Default timezone is UTC
    fsockopen/cURL: 	Your server has fsockopen and cURL enabled.
    SOAP Client: 	Your server has the SOAP Client class enabled.
    WP Remote Post: 	wp_remote_post() was successful - PayPal IPN is working.
    Plugins
    Installed Plugins: 	Intuitive Custom Post Order by hijiri version 2.0.6,
    WooCommerce by WooThemes version 2.0.20,
    WP Nivo Slider by Rafael Cirolini version 3.1
    Settings
    Force SSL: 	No
    WC Pages
    Shop Base:	#39 - /?page_id=39
    Cart:	#40 - /?page_id=40
    Checkout:	#41 - /?page_id=41
    Pay:	#48 - /?page_id=48
    Thanks:	#49 - /?page_id=49
    My Account:	#42 - /?page_id=42
    Edit Address:	#44 - /?page_id=44
    View Order:	#45 - /?page_id=45
    Change Password:	#46 - /?page_id=46
    Lost Password:	#43 - /?page_id=43
    WC Taxonomies
    Order Statuses: 	cancelled (cancelled), completed (completed), failed (failed), on-hold (on-hold), pending (pending), processing (processing), refunded (refunded)
    Product Types: 	external (external), grouped (grouped), simple (simple), variable (variable)
    Theme
    Theme Name:
    Theme Version:
    Author URL:
    Templates
    Template Overrides: 	No core overrides present in theme.
    Thread Starter yiags987

    (@yiags987)

    Hi Obaid,

    I have now solved this issue and can explain a bit how …

    To do what you need you have to take the PHP code of the slider from the index.php code and copy it over to your pages.php page (where you would like the slider to appear).

    You will see ‘category_name’ => ‘some-category-slug’ within the code – jut change the ‘some-category-slug’ page to your slug.

    One thing I found though …. this made the slider appear in every back page. To solve this you need to create 1 custom page template per ‘new instance of slider’.

    I am afraid I do not have time to be really descriptive right now but if you are still stuck – post your code back and I will see if I can help.

    Thread Starter yiags987

    (@yiags987)

    Thank you for your response, it turned out I was being silly!

    ‘category_name’ => ‘some-category-slug’ worked fine – I just had “category” instead of “category_name”. Thank you – my bad!

    Thread Starter yiags987

    (@yiags987)

    Thank you for your response.

    I have tried exactly that:

    ‘category_name’ => ‘interviews’

    The result is that the slider shows images from all recent posts from “Interviews” and “Features” (my 3rd page).

    I only want it to show images from the interviews category and cannot work out why it is showing the other ‘Features’ category as well. The original flex slider on the news page continues to just display ‘news’ posts as it should.

Viewing 5 replies - 1 through 5 (of 5 total)