Database Queries and PHP Code Widget (2 posts)

  1. TradingMetro
    Posted 7 years ago #

    I tried putting the following code in a PHP Code Widget:

      $querystr = "SELECT * FROM resources_posts LEFT JOIN resources_term_relationships ON(resources_posts.ID = resources_term_relationships.object_id)
      LEFT JOIN resources_term_taxonomy ON(resources_term_relationships.term_taxonomy_id = resources_term_taxonomy.term_taxonomy_id) WHERE resources_term_taxonomy.term_id IN (4,7,8,9,12,13) AND resources_term_taxonomy.taxonomy = 'category' AND post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC limit 5";
      $blogposts = $wpdb->get_results($querystr, OBJECT);
      if ($blogposts): ?>
      <?php foreach ($blogposts as $post): ?>
      <?php setup_postdata($post);
      $newpermalink = str_replace(get_bloginfo('url'),"/resources",get_permalink()); ?>

    • " rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?>
    • <?php endforeach; ?>
      <?php else : ?>
      <?php endif; ?>


    I get the following in my widget admin area:
    %BEG_OF_TITLE%Title of Widget%END_OF_TITLE%

    I then have to edit the widget contents from the database because I no longer can edit this widget.

    Is this because PHP Code Widget doesn't like database queries? I tested this code in a PHP template file and it works.

    Any idea why?

  2. camillomiller
    Posted 7 years ago #

    Dunno about the queries,
    but when you got an error with this plugin, before tinkering the database you should try to deactivate the plugin and see if the widget is still in your list. By deactivating you should obtain the old sidebar.

Topic Closed

This topic has been closed to new replies.

About this Topic