Ask your WordPress questions! Pay money and get answers fast! (more info)

Custom post type from plugin not working correctly WordPress

  • SOLVED

Hello,

I have a plugin called "The Events Calendar" that has creates a custom post type called "events". The other day, I posted on wpquestions about how to use a different single post template for different custom taxonomies, categories and tags.

I used the following code in functions.php of my child theme:

// Changing single php for categories and taxonomies

add_filter( 'template_include', 'wpq_template_include' );

function wpq_template_include( $template ) {

global $post;

if(is_single()){

if (in_category('104'))

$template = locate_template(array('single-schol.php', 'single.php'));

elseif (in_category('103'))

$template = locate_template(array('single-schol.php', 'single.php'));

elseif (in_category('107'))

$template = locate_template(array('single-schol.php', 'single.php'));

elseif (in_category('108'))

$template = locate_template(array('single-schol.php', 'single.php'));

elseif (has_tag('DOIhidden'))

$template = locate_template(array('single-DOI.php', 'single.php'));

elseif(has_term('DOI', 'identifier'))

$template = locate_template(array('single-DOI.php', 'single.php'));

else

$template = locate_template(array('single-research.php', 'single.php'));

}

return $template;

}


However, now all my events (under single-events.php) are getting the single-research.php template. Furthermore, the events page "neliti.com/events" isn't working either.

What can be done so the single-event.php file from the plugin works like normal again?

Answers (3)

2015-07-03

timDesain Nanang answers:

you can try following code:

add_filter( 'template_include', 'wpq_template_include' );
function wpq_template_include( $template ) {
global $post;

if(is_single()){
$post_type = $post->post_type;

if (in_category( array( '103', '104', '107', '108' ) ))
$template = locate_template(array('single-schol.php', 'single.php'));
elseif (has_tag('DOIhidden'))
$template = locate_template(array('single-DOI.php', 'single.php'));
elseif (has_term('DOI', 'identifier'))
$template = locate_template(array('single-DOI.php', 'single.php'));

elseif ($post_type == 'post')
$template = locate_template(array('single-research.php', 'single.php'));
}

return $template;
}


this part of your code that will override all single (post dan cpt) templates

else
$template = locate_template(array('single-research.php', 'single.php'));


timDesain Nanang comments:

and the events page neliti.com/events is working properly
please check this page: [[LINK href="http://www.neliti.com/events/month/"]]http://www.neliti.com/events/month/[[/LINK]]

or you can change "Default view" under Events - Setting menu