WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Yet Another Related Posts Plugin] YARPP to support custom Taxonomies? (3 posts)

  1. circlecube
    Member
    Posted 4 years ago #

    Thanks for the awesome plugin!

    I'm using custom taxonomies in my wp and would love for YARPP to be able to use them to calculate the related posts. Seems like it'd be pretty simple to copy the functionality YARPP has with tags for each currently used taxonomy, but what do I know, I didn't build the it =).

  2. asthyanax
    Member
    Posted 4 years ago #

    I'd like to do that too. There's apparently nothing out there to display related posts using custom taxonomy.
    Thanks.

  3. despinosa
    Member
    Posted 4 years ago #

    YARPP is a great plugin and I am very happy about the new templates feature in 3.0, but I too was looking to be able to use the new custom taxonomies in WordPress 2.8.

    I dug into the YARPP code in the plugin folder and made two tiny tweaks to the SQL queries in magic.php and services.php that seem to make this work.

    Definitely make a backup copy of magic.php and services.php before you do this in case anything breaks.

    In services.php on line 26 the original code should look like this,

    foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy = 'post_tag' order by name") as $tag) {

    To add your own custom taxonomies to it change it to look like this,

    foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy in ('post_tag', 'custom_taxonomy_slug') order by name") as $tag) {

    where 'custom_taxonomy_slug' would be the all lowercase slug of your custom taxonomy. For example, if you created a custom taxonomy called People so you could add tags like Johnny, Peter, or Lisa to the People taxonomy, then you would add 'people' as your custom_taxonomy_slug.You could as many different slugs here separated by commas.

    The last change is in magic.php on line 186.

    Change this line

    AND tagtax.taxonomy = 'post_tag')\n";

    to look something like this

    AND (tagtax.taxonomy = 'post_tag' OR tagtax.taxonomy = 'custom_taxonomy_slug'))\n";

    Again, the 'custom_taxonomy_slug' would be the same slug name you used in the first change.

    If everything works you should see your custom taxonomy tags show up in the YARPP settings page in the "Disallow by tag" section.

Topic Closed

This topic has been closed to new replies.

About this Topic