Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Post type/short code stop working after upgrade... WordPress

  • SOLVED

I have a custom post type called memberlist, and wanting to display all post in a category. If I used the shortcode, it will not display some categories (lodging-hotels-motels). But if I use a page template using the same category that would not display via shortcode, works fine. I have attached my shortcode function and then also the page template.

My shortcode: [hes_list cat="lodging-hotels-motels"]



function hes_db_list ($atts, $content= null) {
extract(shortcode_atts(array(
"cat" => ''
), $atts));

#$hes_tag="";
$hes_tag = trim($cat);
echo $hes_tag;
$hes_db_data ="";
global $post;
#$loop = new WP_Query(array('post_type' => 'memberlist','post_status'=> 'publish', 'membership_category' => $hes_tag, 'posts_per_page' => -1, 'order' => 'ASC'));
$loop = new WP_Query(array('post_type' => 'memberlist','post_status'=> 'publish', 'membership_category' => $hes_tag, 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC'));

#echo "<pre>";
#print_r($GLOBALS['wp_query']);
#echo "</pre>";
while ( $loop->have_posts() ) : $loop->the_post();
$custom = get_post_custom($post->ID);

$member_name = $custom["member_name"][0];
$member_contact = $custom["member_contact"][0];
$member_email = $custom["member_email"][0];
$member_address = $custom["member_address"][0];
$member_telephone = $custom["member_telephone"][0];
$member_fax = $custom["member_fax"][0];
$member_website = $custom["member_website"][0];
$member_since = $custom["member_since"][0];
$member_tags = get_post_meta( $post->ID, 'member_tags', true );

$hes_db_data .= '<div id="event-container">';
$hes_db_data .= '<div class="members">';

$hes_title_id = ($post->ID);

$hes_db_data .= '<h1><a href="' . get_permalink($hes_title_id) . '" rel="bookmark">' . get_the_title($hes_title_id) . '</a></h1>';

$hes_db_data .= $member_name .'<BR>';
$hes_db_data .= $member_email .'<BR>';
$hes_db_data .= $member_tags .'<BR>';
$hes_db_data .= '</div><!-- members -->';
$hes_db_data .= '</div><!-- event-container-->';

endwhile;

return $hes_db_data;
}

add_shortcode('hes_list', 'hes_db_list');


#######################################################

And here is the page template code:

<?php
/*
Template Name: ContentWide1
*/
?>

<?php get_header(); ?>

<ul id="nav2">
<?php
#wp_list_pages('title_li=&sort_column=menu_order');
wp_nav_menu( array(
'theme_location' => 'third-menu',
'sort_column' => 'menu_order') );
?>
</ul>

<div id="content">

<?php
#$hes_category = $_POST['listbox1'];
$hes_category ="lodging-hotels-motels";
echo "Category -> ". $hes_category . "<BR>";
global $post;
$loop = new WP_Query(array('post_type' => 'memberlist','post_status'=> 'publish', 'membership_category' => $hes_category, 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC'));
while ( $loop->have_posts() ) : $loop->the_post();
$custom = get_post_custom($post->ID);
$member_name = $custom["member_name"][0];
$member_contact = $custom["member_contact"][0];
$member_email = $custom["member_email"][0];
$member_address = $custom["member_address"][0];
$member_telephone = $custom["member_telephone"][0];
$member_fax = $custom["member_fax"][0];
$member_website = $custom["member_website"][0];
$member_since = $custom["member_since"][0];
?>
<div id="event-container">
<div class="members">
<h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>

<?php the_content(); ?>
<table class="member">
<tr>
<td class="member-info">Name:</td>
<td class="member-data"><?php echo $member_name; ?></td>
<td class="member-space"></td>
<td>Phone:</td>
<td class="member-data"><?php echo $member_telephone; ?></td>
</tr>

</table>

</div><!-- members -->
</div><!-- event-container-->

<?php endwhile; ?>
</div><!-- #content -->

<?php get_footer(); ?>

Answers (1)

2011-07-25

Peter Michael answers:

Try this as your shortcode query:
$loop = new WP_Query(array('post_type' => 'memberlist','post_status'=> 'publish', 'tax_query' => array( array( 'taxonomy' => 'membership_category', 'field' => 'slug', 'terms' => $hes_tag ) ), 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC'));


69developer comments:

Same results.


Peter Michael comments:

I'm assuming 'membership_category' is a custom taxonomy for your custom post 'memberlist'?


69developer comments:


add_action( 'init', 'memberlist_taxonomies' );

function memberlist_taxonomies() {

register_taxonomy(
'membership_category',
array( 'memberlist' ),
array(
'hierarchical' => true,
'labels' => array(
'name' => 'Membership Categories',
'singular_name' => 'Membership Category',
),
'rewrite' => array(
'slug' => 'membership-categories',
'with_front' => false
),
)
);
}


Peter Michael comments:

What does print_r($GLOBALS['wp_query']) say? Do you get results if you run the same query in phpmyadmin?

Maybe post your custom post function here as well or send a [[LINK href="http://pastebin.com/"]]pastebin[[/LINK]] link via PM


69developer comments:

Not for sure how to write the query for phpadmin?

If you PM me your email, I can send you the custom post type code?


Peter Michael comments:

Works fine for me. Have you updated your permalinks?


69developer comments:

Update permalinks? How?

It works ok for some categories but not all. But if the shortcode dosnt work, the page template does?!?


Peter Michael comments:

Go to Settings -> Permalinks and re-save

I made a test post of type member list and added it to the category 'lodging-hotels-motels' just like your example. Then added a normal post with shortcode [hes_list cat="lodging-hotels-motels"] and it works fine.


69developer comments:

Yesh some of the cats work and some dont. I think it has something to do with the posts in the custom post type.


69developer comments:

When upgraded from WP 3.0.1 to latest, the Updating database seem to never have finished.


Peter Michael comments:

Then go to 'Updates' and click Re-install now. You can also go back to your previous version and start the update again, assuming you have made all backups prior the first upgrade ;-)

For the failing categories, you need to run the query in phpmyadmin or something:

SELECT wp_posts.* FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN (8) )
AND wp_posts.post_type = 'memberlist'
AND (wp_posts.post_status = 'publish')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_title ASC


Make sure you query the correct taxonomy_id (membership_category ID) for each category you think it doesn't work and see if you get results.


69developer comments:

That in phpmyadmin worked and returned the results.


Peter Michael comments:

And what do you get on the post with the shortcode? An empty page? Can you see title & content? echo $hes_tag displays the correct category?


69developer comments:

It returns nothing. It does not list the content or the post from the shortcode.

Yes $hes_tag is displaying the correct category, as I echoed to make sure.


69developer comments:

Also you getting my emails?


Peter Michael comments:

Replied via email now, you landed in spam ;-)


Peter Michael comments:

Please close this question as well, thanks.