-
Author
Tagged: plugin, event manager, custom post, Related Posts, single
-
October 4, 2015 at 21:36 #80817KlameParticipant
It dont work for me…
I have enabled the “Enable custom posts related” under theme options -> blog.But don’t get anything on my single-cpt.php page.
I came across this code on page-parts/post-related
/* Query args */
$args=array(
‘post__not_in’ => array($post->ID),
‘showposts’=> 8,
‘orderby’ => ‘rand’ //random posts
);//logic for blog posts
if (is_singular(‘post’)) {//related text
$related_text = __(“Related Articles”, “kleo_framework”);$categories = get_the_category($post->ID);
if (!empty($categories)) {
$category_ids = array();
foreach ($categories as $rcat) {
$category_ids[] = $rcat->term_id;
}$args[‘category__in’] = $category_ids;
}
}
// logic for custom post types
else {//related text
$related_text = __(“Related”, “kleo_framework”);global $post;
$categories = get_object_taxonomies($post);if (!empty($categories)) {
foreach( $categories as $tax ) {
$terms = wp_get_object_terms($post->ID, $tax, array(‘fields’ => ‘ids’));$args[‘tax_query’][] = array(
‘taxonomy’ => $tax,
‘field’ => ‘id’,
‘terms’ => $terms
);
}
}
}And thought “Hey, I should definitely do something about this!
Probably this line: $categories = get_the_category($post->ID);
You sir, are a GENIUS!
”
But then I realised.. I’m not a genius!
I dont know what to?
What does $post->ID tells you?My custom post type is made by this plugin:
https://wordpress.org/plugins/events-manager/It is using codes like this:
echo $EM_Event->output(‘#_CATEGORYNEXTEVENT’);
To get related post (But they are not very pretty, and for me, not easy to style)If that makes any difference. 🙂
Thanks
October 5, 2015 at 17:32 #80946sharmstrModeratorAccording to the plugin, you cant use query_posts to get the events. That’s what the related code uses. You can test this yourself by changing
COPY CODEquery_posts($args);
COPY CODEquery_posts("post_type=event");
What that *should* do is return all events regardless of event_categories and event_tags. You’ll see that it doesnt.
You’ll have to use WP_Query instead. There’s a ton of info on their site about how to use it.
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
-
AuthorPosts
The forum ‘KLEO’ is closed to new topics and replies.