• Hiya. I’m using a paid-for theme that I have since discovered doesn’t provide tweaking support and I am stuck needing one tiny tweak that I cannot for the life of me make work.

    BACKSTORY: Site is for a band. Theme has a custom post archive called Album. This has an audio player which streams audio/sells from Bandcamp. Custom Posts are Album posts. However, I need another archive called Singles/EPs which would be styled in the same way.
    Currently Albums and Singles show all custom posts.

    Has anyone any idea how I could add a category to the custom posts page/archive so I can have seperate, filtered archive pages?

    Can provide the code if needs be, I’m really stumped on something really important

    Many Cheers

    Andy

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    If I understand you correctly, you want the standard category meta box like we see on regular post edit screens to appear on the album CPT edit screen. First pull down the Screen Options tab on the Album edit screen and be sure it’s really not there or if it just needs to be made visible through this interface.

    If it’s really not there, you need to add category support for the album CPT. Use register_taxonomy_for_object_type(). This must be called after the album CPT is registered. CPTs are often registered from a hook to “init”. Check your theme’s code to confirm this. You can use the same hook, but use a larger priority in your hook so it runs after the theme’s hook. If the theme’s hook does not specify a priority (third parameter to add_action()), the default is 10. Thus if you hooked with a priority of 20, yours will run after the theme’s.

    Thread Starter Andy Woggle

    (@andy-woggle)

    Yep, you’ve got it, there is no option for Categories in the pull-down Screen Options.
    I’ve looked in both almbum.php and album-archive php but I can’t seem to figure where the hook would be

    Here’s the code for the album CPT. If you could figure this, I’d be eternally in your gratitude BcWorkz!

    <div id="post-<?php the_ID(); ?>" <?php post_class('media-block'); ?>>
    	<?php if(get_field('alb_link_external')): ?>
    	<a target="_blank" href="<?php echo get_field('alb_link_external'); ?>">
    	<?php else: ?>
    	<a href="<?php the_permalink(); ?>">
    	<?php endif; ?>
    		<div class="holder">
    			<div class="image"><?php the_post_thumbnail( array(216,216) ); ?></div>
    			<div class="text-box">
    				<i class="media-decoration media-audio fa fa-headphones"></i>
    				<h2><?php the_title(); ?></h2>
    				<?php if(get_field('alb_release_date') != '') : ?>
    				<time class="datetime" datetime="<?php echo date( 'c', strtotime( get_field('alb_release_date') ) ); ?>"><?php echo __("Release date", IRON_TEXT_DOMAIN); ?> <?php the_field('alb_release_date'); ?></time>
    				<?php endif; ?>
    			</div>
    		</div>
    	</a>
    </div>

    Cheers!

    Andy

    Moderator bcworkz

    (@bcworkz)

    Thanks for the effort, but that’s not it. We can likely blindly add our function call in a way that is more than likely late enough. Try adding this to your theme’s functions.php:

    function aw_cat_album_support() {
       register_taxonomy_for_object_type( 'category', 'album' );
    }
    add_action('init', 'aw_cat_album_support', 100 );

    Confirm that ‘album’ is the correct CPT slug. When you visit the albums list page in the back end, look at the browser address’ post_type= parameter. Whatever follows is the proper slug.

    If this works, you should move the code to a location where it will not be lost when your theme is updated. Either create a custom child theme (if your theme is not already a child) or custom plugin for your code. You can add any other customizing code to the same location.

    Thread Starter Andy Woggle

    (@andy-woggle)

    Hi again Bcworx

    Sadly, this did not do anything at all. I tried checking in the screen options also, but to no avail on either the archive or the CPT page.

    I’ve found a workaround in that I’ll rename the CPT to Audio and all can go there instead. Sloppy, but this is proving a nightmare.

    Thanks for trying though. Much appreciated

    Andy

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding category to cutom post type page editor’ is closed to new replies.