dunc
Forum Replies Created
-
tax_query fixed it. Thanks for the tip about the deprecated code @lopo.
So to answer OPs question, yes working fine on multisite.
Hi,
I’m using it on a multisite and may have come across a problem.
I have a custom post type. After cloning a post the original becomes unavailable to get_post().
Here’s an example:
You can see both products in search results (the version with ‘NRC/CAC’ in the name is the clone):
http://www.globalgreentag.com/?archive_template=search.php&s=Fissured&post_type=productsHere is a single page template for the CPT ‘manufacturers’ with a get_post() at the bottom to display posts from the CPT ‘products’ based on a taxonomy. Only the clone ‘NRC/CAC’ is shown:
http://www.globalgreentag.com/manufacturer/armstrong-world-industries-ceiling-division/This product is missing (the original):
http://www.globalgreentag.com/products/fine-fissured-fine-fissured-planks-and-fine-fissured-high-nrc/In the search results you can see they both have the same manufacturer (taxonomy) so they should both appear on the manufacturer page above.
We have numerous examples and the common thread is that it’s the original that goes m.i.a.
Here’s a copy of my get_post() code that I’m using on my single manufacturer template :
<?php global $post; $slug = get_post( $post )->post_name; $manproducts = get_posts( array( 'numberposts' => -1, // we want to retrieve all of the posts 'post_type' => 'products', 'manufacturer' => $slug, 'suppress_filters' => false ) ); if( $manproducts ) { ?><h3>Products</h3> <div class="post-grid"> <div class="grid-items"> <?php foreach ( $manproducts as $manproduct ) { ?><div class="item"> <div class="layer-media"> <?php if ( has_post_thumbnail( $manproduct->ID ) ) { ?> <a href="<?php echo get_permalink( $manproduct->ID ) ?>" title="<?php echo get_the_title( $manproduct->ID ); ?>"> <?php echo get_the_post_thumbnail( $manproduct->ID, 'medium' ); ?> </a> <?php } ?> </div> <div class="layer-content"> <h4><a href="<?php echo get_permalink( $manproduct->ID ) ?>" title="<?php echo get_the_title( $manproduct->ID ); ?>"><?php echo get_the_title( $manproduct->ID ); ?></a></h4> </div> </div> <?php } ?> </div> </div> <?php } wp_reset_query(); ?>FYI – I’m using the plugin CPT-onomies to create the ‘manufacturer’ CPT and Taxonomy.
Any ideas?
Thanks!
– DuncanForum: Hacks
In reply to: Show posts with the same tags as the current pageHi bcworkz.
I got fed up and went on holiday, and with a fresh mind I’ve thought of a completely different way to achieve what we need. It’s a shame we didn’t resolve my original problem but hopefully someone will find use in this thread. Thank you for your help!
My solution:
I’ve added two custom fields to post_tags, an image (logo) and a custom URL for the page I want to link to (custom fields were added using plugin Ultimate Taxonomy Manager).
Then I can simply call the tags from the main post, including the custom URL, and display a list of links to those pages. This approach works for us because we’re only displaying a list of brand names which rarely change, so maintaining this is simple enough.
See it in action (at bottom of page):
http://www.livingsound.com.au/residential/smart-home-automation/// Display a list of post_tags with a custom link and logo, if the custom URL is set (the custom fields 'logo' and 'custom_url' were added to post_tags using Ultimate Taxonomy Manager plugin) global $post; $tags = wp_get_post_terms( $post->ID , 'post_tag' ); if ($tags) { echo "<table>"; foreach ($tags as $tag) { $customurl = xydac_cloud('post_tag', $tag->slug, 'custom_url'); if (!empty($customurl)) { ?> <tr> <td width="170" class="brand-logo-td"> <a href="<?php echo xydac_cloud('post_tag', $tag->slug, 'custom_url'); ?>" rel="bookmark" title=""><img src="<?php echo xydac_cloud('post_tag', $tag->slug, 'logo'); ?>" border="0" alt=""></a> </td> <td> <h3><a href="<?php echo xydac_cloud('post_tag', $tag->slug, 'custom_url'); ?>" rel="bookmark" title=""><? echo $tag->name;?> ยป </a></h3> </td> </tr> <?php } } echo "</table>"; }Forum: Hacks
In reply to: Show posts with the same tags as the current pageBTW – may latest code is not showing any posts (bottom of page):
http://www.livingsound.com.au/residential/smart-home-automation/Forum: Hacks
In reply to: Show posts with the same tags as the current pageHi bcworks. You are a true teacher. ๐
I’ve made the changes you suggested (and learnt more about arrays along the way).
Unfortunately it’s still not working and I can’t understand why.
I’ve changed to arrays and I took your point about mixing strings and arrays and have changed the post_type to an array also: array(‘brand’);
global $post; $found_none = '<h2>No related posts found!</h2>'; $do_not_duplicate = array(); $do_not_duplicate[] = $post->ID; $tags = wp_get_post_terms( $post->ID , 'post_tag' ); if ($tags) { $tag_array = array(); foreach( $tags as $tag ) { $tag_array[] = $tag->term_id; // save the id in the array } foreach ($tags as $tag) { $myargs=array( 'tag__in' => $tag_array, 'post__not_in' => $do_not_duplicate, 'post_type' => array('brand'), 'posts_per_page'=>-1, 'caller_get_posts'=>1 ); $my_query = new WP_Query($myargs); if( $my_query->have_posts() ) : while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate[] = $post->ID; ?> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> <?php $found_none = ''; endwhile; wp_reset_postdata(); endif; } } if ($found_none) { echo $found_none; } wp_reset_query(); // to use the original query again print_r($tag_array); // for testing purposes to check tag ID array is workingMaybe it’s time for the teacher to take over. ๐
Thanks for all your help so far! We must be close!
Forum: Hacks
In reply to: Show posts with the same tags as the current pageThanks for those tips. I’ve tried avoiding global $post and in the loop I replaced $post with $brand but they had no effect.
I’ve also tested WP_Query instead of get_posts() but the result was the same.
Before digging into query.php I’ve tried a new approach using ideas from this post (MichaelH again).
I am now getting a list of all the posts from the post_type ‘brand’, which means post_type is being recognised which is great. But when I try to include a list of tags from the global $post nothing is shown. I’ve tried different WP_Query tag parameters like tag, tag_id, tag_slug__in, etc.
Can you see any obvious problems in the code below that would create a problem with the tag__in bit? (note: tag__in is commented out at the moment because with it the output is ‘No related posts found!’. You can see this code in action here)
global $post; $found_none = '<h2>No related posts found!</h2>'; $post_types = 'brand'; $do_not_duplicate[] = $post->ID; $tags = wp_get_post_terms( $post->ID , 'post_tag' ); if ($tags) { $tag_array = array(); foreach( $tags as $tag ) { $tag_array[] = $tag->term_id; // save the id in an array } $tag_string = implode(", ",$tag_array); foreach ($tags as $tag) { $myargs=array( // 'tag__in' => array($tag_string), 'post__not_in' => $do_not_duplicate, 'post_type' => 'brand', 'showposts'=>-1, 'caller_get_posts'=>1 ); $my_query = new WP_Query($myargs); if( $my_query->have_posts() ) : while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate[] = $post->ID; ?> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> <?php $found_none = ''; endwhile; wp_reset_postdata(); endif; } } if ($found_none) { echo $found_none; } wp_reset_query(); // to use the original query again echo $tag_string; // for testing purposes to check tag IDs are workingI did a further test which was to replace the WP_Query loop above with the get_posts() loop from my previous attempt and I think you are correct in assuming get_posts() is mishandling the arguments because post_type ‘brand’ was ignored again, with get_posts() and instead I got a long list of the global post title.
Forum: Hacks
In reply to: Show posts with the same tags as the current pageHi bcworkz
I went looking for an existing plugin that did what I needed but still couldn’t find anything.
So I’ve returned to my code and come up with this. I’m a bit closer now but it’s still not working:
global $post; $tags = get_the_tags(); // get an array of all the tags as objects. $tag_array = array(); foreach( $tags as $tag ) { $tag_array[] = $tag->term_id; // save the id in an array } $tag_string = implode(",",$tag_array); $myargs = array( 'tag__in' => array($tag_string), 'post_type' => 'brand', 'showposts'=>-1, 'caller_get_posts'=>1 ); $brands = get_posts( $myargs ); // The Loop foreach ($brands as $post) : setup_postdata($post); echo '<p>'; the_title(); echo '</p>'; endforeach; // Reset Post Data wp_reset_postdata(); echo $tag_string; // for testing purposes to check tag IDs are workingAs you can see I’m extracting the post IDs properly now, and passing them to tag__in. The echo at the bottom shows my tag IDs are working.
The problem is the argument ‘post_type’ appears to be ignored by the loop. Instead I’m getting only a repeat of the current page (a ‘page’). See the bottom of:
http://www.livingsound.com.au/residential/smart-home-automation/I wonder if the problem is that my global $post is a ‘page’? I’ve enabled tags for pages using this plugin:
http://ww.wp.xz.cn/plugins/tag-pages/This person wonders if post_type being ignored is a bug:
http://ww.wp.xz.cn/support/topic/post_type-is-ignored-when-i-include-tag_in-in-my-get_posts-queryThanks for you help! I’m way in over my head now!
– Duncan
I’m having this problem too. Did you find a resolution to this?
My code is a bit more complex but the effect is the same. I’ve tried get_posts and WP_Query loops to no avail.
// List posts from a custom post type, that share tags with the current post global $post; $tags = get_the_tags(); // get an array of all the tags as objects. $tag_array = array(); foreach( $tags as $tag ) { $tag_array[] = $tag->term_id; // save the id in an array } $tag_string = implode(",",$tag_array); $myargs = array( 'post_type' => 'brand', 'tag__in' => array($tag_string), 'showposts'=>-1, 'caller_get_posts'=>1 ); $brands = get_posts( $myargs ); // The Loop foreach ($brands as $post) : setup_postdata($post); echo '<p>'; the_title(); echo '</p>'; endforeach; // Reset Post Data wp_reset_postdata();Forum: Hacks
In reply to: Show posts with the same tags as the current pageI’m searching for a plugin option. Something like this would be great if it supported Custom Post Types:
http://ww.wp.xz.cn/plugins/posts-by-tag/Forum: Plugins
In reply to: [Posts By Tag] Custom Post TypesGreat plugin! Please accept my vote for CPT support.
Thanks.Forum: Plugins
In reply to: [Contact Form 7] [Plugin: Contact Form 7] No tag choices and No form titlesSame for me.
I’ve just installed CF7 3.1 on WP 3.2.1 multisite.Until there is a fix for this tags can be created the old fashioned way. Instructions are here:
http://contactform7.com/tag-syntax/Same for me.
I’ve just installed CF7 3.1 on WP 3.2.1 multisite.
Forum: Plugins
In reply to: [Mailing List] Mailing List Plugin settings not there in 3.3.1I’ve fixed it. There was a conflict with WP Example Content plugin, which I have now deactivated, and Mailing List settings have appeared in the Dashboard. ๐
Here’s a post about a similar issue which led me to the solution.
Forum: Plugins
In reply to: [Quick Post Widget] [Plugin: Quick Post Widget] Checklist Problem fixedI’ve just remembered that you need to be logged in to see the form!
Here’s a screengrab so you can see what I’m talking about:
http://publishbluemountains.com.au/images/screenshot.jpgForum: Plugins
In reply to: [Quick Post Widget] [Plugin: Quick Post Widget] Checklist Problem fixedhttp://publishbluemountains.com.au/bl-form-test/
Both the ‘Categories’ checklist and my custom taxonomy checklist ‘Listing Categories’ show the HTML code.
Drop-down menus are fine.
Quickpost Widget 1.9 (downloaded today)
I’m using WP 3.2.1 in multisite
Buddypress 1.2.9Thanks! ๐