WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
How to add custom post type to titles and metas? (2 posts)

  1. FreshFromTheGrave
    Member
    Posted 1 year ago #

    Hey guys, I've found some information on this but not enough for me to solve it myself. I'm trying to get a custom post type to show up on the titles and metas page but I don't know how. I realise this is more to do with the theme than anything else and that whatever the plugin looks for in the custom post types isn't there (has_archives?).

    What do I have to do to get a custom post type to show up?

    Thanks for any help!

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. FreshFromTheGrave
    Member
    Posted 1 year ago #

    OK so I've added 'has_archive' => true, to the custom post type in post-types.php but it still doesn't show up. my portfolio post type looks like this:

    /*************** PORTFOLIO POST-TYPES  ****************/
    add_action('init', 'portfolio_register');
    
    function portfolio_register() {	
    
    	register_post_type( 'portfolio' ,
    						array(
    							'label' => 'Portfolio',
    							'singular_label' => 'Portfolio',
    							'exclude_from_search' => false,
    							'publicly_queryable' => true,
    							//'rewrite' => array('with_front' => false),
    							'show_ui' => true,
    							'query_var' => true,
    							'capability_type' => 'post',
    							'has_archive' => true,
    							'hierarchical' => false,
    							'edit_item' => __( 'Edit Work', 'Epic'),
    							'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields', 'comments', 'revisions')
    						)
    					);
    
    	register_taxonomy( 'portfolio_category',
    						'portfolio',
    						array( 'hierarchical' => true,
    								'label' => __('Categories', 'Epic'),
    								'singular_label' => __('Category', 'Epic'),
    								'public' => true,
      								'show_tagcloud' => false,
    								'query_var' => 'true',
    			 					'rewrite' => array('slug' => 'portfolio_category' , 'with_front' => false)
    						)
    					);  
    
    	add_filter('manage_edit-portfolio_columns', 'portfolio_edit_columns');
    	add_action('manage_posts_custom_column',  'portfolio_custom_columns');
    
    	function portfolio_edit_columns($columns){
    		$columns = array(
    			'cb' => '<input type="checkbox" />',
    			'title' => 'Title',
    			'portfolio_category' => 'Category',
    			'portfolio_description' => 'Description'
    		);
    
    		return $columns;
    	}
    
    	function portfolio_custom_columns($column){
    		global $post;
    		switch ($column)
    		{
    			case "portfolio_category":
    				echo get_the_term_list($post->ID, 'portfolio_category', '', ', ','');
    				break;  
    
    			case 'portfolio_description':
    				the_excerpt();
    				break;  
    
    			case 'portfolio_image':
    				the_post_thumbnail( 'portfolio1' );
    				break;
    		}
    	}
    }
    
     function my_post_type_link_filter_function( $post_link, $id = 0, $leavename = FALSE ) {
        if ( strpos('%portfolio_category%', $post_link)  < 0 ) {
          return $post_link;
        }
        $post = get_post($id);
        if ( !is_object($post) || $post->post_type != 'portfolio' ) {
          return $post_link;
        }
        $terms = wp_get_object_terms($post->ID, 'portfolio_category');
        if ( !$terms ) {
          return str_replace('portfolio/category/%portfolio_category%/', '', $post_link);
        }
        return str_replace('%portfolio_category%', $terms[0]->slug, $post_link);
      }
    
      add_filter('post_type_link', 'my_post_type_link_filter_function', 1, 3);
    
    ?>

    Does anyone have any other tips as to what I can do to get the plugin to recognise my Portfolio post type? The Slider post type is being recognised and that one works if I add has_archive to it. The code for the slider type in my post-types.php looks like this:

    <?php
    /*************** SLIDER POST-TYPES  ****************/
    add_action('init', 'slider_items_register');
    
    function slider_items_register()
    {
    	register_post_type( 'slider' ,
    		array(
    			'label' => 'Slider Items',
    			'singular_label' => 'Slider Item',
    			'public' => true,
    			'show_ui' => true,
    			'capability_type' => 'post',
    			'hierarchical' => false,
    			'rewrite' => true,
    			'supports' => array('title', 'thumbnail', 'editor')
    		)
    	);
    
    	//add_filter('manage_edit-slider_columns', 'slider_edit_columns');
    	//add_action('manage_posts_custom_column',  'slider_custom_columns');	
    
    }
    
    add_action("admin_init", "add_slide");
    add_action('save_post', 'update_slide_url');
    
    function add_slide()
    {
    	add_meta_box("slider_details", "Slider Options", "slider_options", "slider", "normal", "low");
    }
    
    function slider_options()
    {
    	global $post;
    	$custom = get_post_custom($post->ID);
    	$slide_url = isset($custom["slide_url"][0]) ? $custom["slide_url"][0] : '';
    	?>
    	<div class="al_input">
    		<label for="slideurl">Slide URL:</label>
    		<input name="slide_url" id="slideurl" value="<?php echo $slide_url; ?>" />
    		<small>Url the slide refers to. Leave blank if you don't want it to be a link.</small><div class="clearfix"></div>
    	</div>
    	<?php
    }
    
    function update_slide_url()
    {
    	global $post;
    	if(isset($_POST["slide_url"]))
    	update_post_meta($post->ID, "slide_url", $_POST["slide_url"]);
    }
    
    add_filter("manage_edit-slider_columns", "slider_edit_columns");
    add_action("manage_posts_custom_column",  "slider_columns_display");
    
    function slider_edit_columns($portfolio_columns){
    	$slider_columns = array(
    		"cb" => "<input type=\"checkbox\" />",
    		"title" => "Project Title",
    		"description" => "Description",
    		"slide_url" => "Slide url"
    		//'slider_image' => 'Image',
    	);
    	return $slider_columns;
    }
    
    function slider_columns_display($slider_columns){
    	switch ($slider_columns)
    	{
    		case "description":
    			the_excerpt();
    			break;
    		//case 'slider_image':
    		//	the_post_thumbnail( 'gallery' );
    		//	break;
    		case 'slide_url':
    			$custom = get_post_custom();
    			echo $custom['slide_url'][0];
    			break;
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic