Forums

How do I fix this tag (4 posts)

  1. rondelw
    Member
    Posted 4 years ago #

    Hello...I have this code:

    <?php
    $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories");
    foreach ($link_cats as $link_cat) {
    ?>
    <li id="linkcat-<?php echo $link_cat->cat_id; ?>"><h4><?php echo $link_cat->cat_name; ?></h4>

      <?php wp_get_links($link_cat->cat_id); ?>

    <?php } ?>

    and it's giving me this error:

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
    SELECT cat_id, cat_name FROM

    What do I need to fix? I'm not smart enough to fix it on my own... =)

  2. Kafkaesqui
    Moderator
    Posted 4 years ago #

    Just updated WordPress, or switched to a new theme? See:

    http://wordpress.org/support/topic/135564

    In summary, database tables specific to categories and links were merged and changed in 2.3 to terms, term_taxonomy and term_relationships. Your options are to remove the code and use the newer wp_list_bookmarks() template tag, or to alter the SELECT to:

    SELECT $wpdb->terms.term_id as cat_id, $wpdb->terms.name as cat_name FROM $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id WHERE $wpdb->term_taxonomy.taxonomy = 'link_category'

    Dropping the query and moving to wp_list_bookmarks() is the smarter alternative, since it better 'future-proofs' your theme against changes in WordPress.

  3. rondelw
    Member
    Posted 4 years ago #

    So what should the replacement code look like? This:

    <?php

    SELECT $wpdb->terms.term_id as cat_id, $wpdb->terms.name as cat_name FROM $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id WHERE $wpdb->term_taxonomy.taxonomy = 'link_category' {
    ?>
    <li id="linkcat-<?php echo $link_cat->cat_id; ?>"><h4><?php echo $link_cat->cat_name; ?></h4>

    <?php wp_get_links($link_cat->cat_id); ?>

    <?php } ?>

  4. rondelw
    Member
    Posted 4 years ago #

    i figured out the answer is just to replace the category tag with this code:

    <?php wp_list_bookmarks('title_li=&category_before=&category_after='); ?>

    and that solved the problem...thanks for pointing me in the right direction.

Topic Closed

This topic has been closed to new replies.

About this Topic