Display Category for Custom Post type

Posted in: Newspaper
Post count: 39

Everything with Newspaper 8.0 is fantastic, the only issue is for our custom post type it will not display the category. Is there something we need to do to ensure this is sorted out?

Post count: 20685

Hi,

That depends on where you want it to display. The modules for example will not display custom taxonomies, only default categories.
In the post page you can choose to display from the available taxonomies, in the CPT&Taxonomy section in the theme panel
https://forum.tagdiv.com/custom-post-type-support/
Those are the only options and settings for custom post types available at the moment. There could be more support added in future updates, but I could not say for sure when this will happen.

Thanks

Post count: 39

I have that set already. Have it set so it knows what category to pull from. It still will not display in modules. I have it to pull from standard categories. since the custom post type uses the same cats as the regular posts.

Any ideas? I can show the settings if need be

Post count: 20685

Hi,

Maybe the category tag is not enabled for that module, if it is not displaying standard categories
https://forum.tagdiv.com/category-tag-on-modulesblocks/
You could try setting a primary category for the posts, in order to control the category tag that is displayed on the module
https://forum.tagdiv.com/primary-category/

Thanks

Post count: 39

Okay, I have checked and it everything is setup as it should be. I have a feeling since this is a custom post type we need to add the “reviews” post type to a class that pulls in the category.

you can see here we have the primary category set:

https://screenpresso.com/=vT35f

and you can see here the standard Category shows as normal, but the custom post type does not.

https://screenpresso.com/=MrQX

I just need to know where to edit to ensure it pulls the category for both the custom post type and the standard posts

You can also see here, I have setup the CPT settings as they should be:

https://screenpresso.com/=OdeIe

Please let me know if you need to see any other settings or what we can do to make this fix.

Post count: 39

Okay I sorted out the issue, although not sure why this is the case. In the file td_module.php on line 488 the segment:

global $wp_query;
$current_queried_term = $wp_query->get_queried_object();

if ( $current_queried_term instanceof WP_Term ) {
$current_term = term_exists( $current_queried_term->name, $current_queried_term->taxonomy );

if ($current_term !== 0 && $current_term !== null) {
$selected_category_obj = $current_queried_term;
}
}

// Get and validate the custom taxonomy according to the validated queried term
if (!empty($selected_category_obj)) {

$taxonomy_objects = get_object_taxonomies($this->post, 'objects');
$custom_taxonomy_object = '';

foreach ($taxonomy_objects as $taxonomy_object) {

if ($taxonomy_object->_builtin !== 1 && $taxonomy_object->name === $selected_category_obj->taxonomy) {
$custom_taxonomy_object = $taxonomy_object;
break;
}
}

// Invalid taxonomy
if (empty($custom_taxonomy_object)) {
return $buffy;
}

$selected_category_obj_id = $selected_category_obj->term_id;
$selected_category_obj_name = $selected_category_obj->name;
}

needs to be changed to:

$td_post_theme_settings = td_util::get_post_meta_array($this->post->ID, 'td_post_theme_settings');
if (!empty($td_post_theme_settings['td_primary_cat'])) {
//we have a custom category selected
$selected_category_obj = get_category($td_post_theme_settings['td_primary_cat']);
} else {

//get one auto
$categories = get_the_category($this->post->ID);

if (is_category()) {
foreach ($categories as $category) {
if ($category->term_id == get_query_var('cat')) {
$selected_category_obj = $category;
break;
}
}
}

if (empty($selected_category_obj) and !empty($categories[0])) {
if ($categories[0]->name === TD_FEATURED_CAT and !empty($categories[1])) {
$selected_category_obj = $categories[1];
} else {
$selected_category_obj = $categories[0];
}
}
}

if (!empty($selected_category_obj)) {
$selected_category_obj_id = $selected_category_obj->cat_ID;
$selected_category_obj_name = $selected_category_obj->name;
}

Once this is done it all worked as intended:

https://screenpresso.com/=jq1Kb

Now, this does not sound like the ideal way to do things, but it does work. If you have advice on a better way, I would be very open to hearing your ideas.

Post count: 20685

Hi,

If it works, just leave it like that. This may be a solution for other users as well, until support in the theme by default will be added in future updates.

Thanks

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