hash95
Forum Replies Created
-
Forum: Plugins
In reply to: [Plugin: Yet Another Related Posts Plugin] Custom post typesThis how I modify it to accept Custom Post Type (for example : video):
single.php :
related_posts('video');related-functions.php :
> line 7function related_posts($posttype = 'post', $a = array(),$echo=true,$reference_ID=false) { return yarpp_related(array($posttype),$a,$echo,$reference_ID); }magic.php :
> line 283 (maybe the number of the lines are wrong)// get the related posts from postdata, and also construct the relate_IDs array
$yarpp_related_postdata = get_post_meta($reference_ID,YARPP_POSTMETA_RELATED_KEY,true);– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Here we have to modify how it get the related ID (of posts).
This is how it works :
1) yarpp.php// update cache on save
add_action(‘save_post’,’yarpp_save_cache’);->
2) magic.php
function yarpp_save_cache($post_ID,$force=true)
if (yarpp_get_option('cross_relate')) $type = array('post','page'); elseif ($post_type == 'page') $type = array('page'); elseif ($post_type == 'video') $type = array('video'); else $type = array('post');3) magic.php
function yarpp_cache_enforce($type=array(‘post’),$reference_ID,$force=false)
->
$related = $wpdb->get_results(yarpp_sql($type,array(),true,$reference_ID), ARRAY_A);4) magic.php
function yarpp_sql($type,$args,$giveresults = true,$reference_ID=false,$domain=’website’)
if ($type == array('page') && !$cross_relate) $newsql .= " and post_type = 'page'"; elseif ($type == array('video')) $newsql .= " and post_type = 'video'"; else $newsql .= " and post_type = 'post'";You can improve the script trying to accept multiple Custom Post Type :
related_posts(array(‘video’,’portfolio’,’gallery’));
…