I have this piece of code, it's works great. I use it with CPTs as seen below 'post_type' => mortgage-home-loan
. I'm trying to use it on another website which is more or less identical but with a different CPT slug property-for-sale
but for some reason the code crashes my page. If I paste in the original mortgage-home-loan
slug then it doesn't crash!
In my notepad++ something weird happens... the for
part of property-for-sale
is in a different colour (try it yourself). Which makes me think the for
part of the slug is causing the crash... is this a WP bug or my fault?
original code... no problem
<?php
if ( is_single()) {
$categories = get_the_category();
if ($categories) {
foreach ($categories as $category) {
$cat = $category->cat_ID;
$args=array(
'cat' => $cat,
'order' => asc,
'post_type' => mortgage-home-loan,
//'orderby' => rand,
'post__not_in' => array($post->ID),
'posts_per_page'=>9999,
'caller_get_posts'=>1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
// echo '<p>Check out our other '. $category->cat_name . ' products</p>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_title(); ?>
<?php
endwhile;
}}} wp_reset_query(); }
?>
New code... crashes the page
<?php
if ( is_single()) {
$categories = get_the_category();
if ($categories) {
foreach ($categories as $category) {
$cat = $category->cat_ID;
$args=array(
'cat' => $cat,
'order' => asc,
'post_type' => property-for-sale,
//'orderby' => rand,
'post__not_in' => array($post->ID),
'posts_per_page'=>9999,
'caller_get_posts'=>1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
// echo '<p>Check out our other '. $category->cat_name . ' products</p>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_title(); ?>
<?php
endwhile;
}}} wp_reset_query(); }
?>