Database Queries and PHP Code Widget
-
I tried putting the following code in a PHP Code Widget:
`-
<?php
$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?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Database Queries and PHP Code Widget’ is closed to new replies.