Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




Upgrade to 1.2.2 disables WP_Query in template?

UserPost

7:43 am
June 18, 2010


cburtbcit

Member

posts 5

1

Greetings and thanks for all of the great work!

I work for a regional government and we've implemented WordPress 2.9.2 in combination with the Role Scoper plugin in order to assist organizations in restricting editing access to specific content on their Web sites. This has been working fantastically, but yesterday I upgraded to 1.2.2 and found that content on the front page of the site was suddenly missing unless I was logged into the WordPress back-end.

As part of trying to solve this problem I upgraded Role Scoper to 1.2.3 and found that the issue still persisted. I examined my roles and and assignments and couldn't find a single restriction that would stop content from being displayed to users that aren't logged in. Finally I stumbled across the "Access Types" section of the "Realm" tab in the Role Scoper options and found the "Viewing content (front-end)" option to be checked under "Apply Roles and Restrictions for:". Unchecking this box and saving my settings restored the content to the front page for users that are not logged in.

This brings me to the question: if I do not have Roles and Restrictions applied to users that aren't logged in (something I wasn't even aware was possible) does content called from WP_Query immediately become unavailable to those users if I have the aforementioned option enabled? 

Thanks again!

7:59 am
June 18, 2010


Kevin

Admin

posts 2503

2

cburtbcit said:

… if I do not have Roles and Restrictions applied to users that aren't logged in (something I wasn't even aware was possible) does content called from WP_Query immediately become unavailable to those users if I have the aforementioned option enabled? 


The option you disabled makes Role Scoper inoperative for all front end access, regardless of whether the user is logged in or not.

Do I understand correctly that your theme is making use of a custom call to WP_Query? If so, please post that code so I can determine what's going wrong.

8:28 am
June 18, 2010


Kevin

Admin

posts 2503

3

I just tested this using the following syntax:

$test_posts = new WP_Query("cat=4");

…and don't see any problem. As I said, I'll need to know what call syntax you're using. Also let me know what template file the call is in (and where you've put it in relation to the "normal" code in that file).

8:46 am
June 18, 2010


cburtbcit

Member

posts 5

4

The call is actually filtering out non-sticky posts along with posts from a couple categories like so:


$query = array(

'category__not_in' => array(5,6),
'post__in' => get_option('sticky_posts'),

);

$queryObject = new WP_Query($query);


From what I understand, using $query in your own WP_Query call is ill-advised, but I don't believe that's causing the problem. The rest of the loop is pretty standard. Thanks!

9:11 am
June 18, 2010


Kevin

Admin

posts 2503

5

Where is that call being done in relation to the rest of the WordPress execution flow?

9:15 am
June 18, 2010


Kevin

Admin

posts 2503

6

Is that syntax error (trailing comma after last array element) in your template code or just in the excerpt you posted here?

10:02 am
June 18, 2010


cburtbcit

Member

posts 5

7

I have two separate WP_Query calls previous to this using separate variables to store the query objects for them. Both of those appear to work when the site loads incorrectly. The third WP_Query call loads only one post when Role Scoper has the front-end content restriction ability enabled. So I suppose my initial post saying that it disable content isn't entirely accurate. The final WP_Query call in the template file doesn't load at all in this condition. It looks like this:

<?php query_posts( array('post__in'=>get_option('sticky_posts'), 'category__not_in' => array(5,6) ) ); ?>And as for the trailing comma, that's not a syntax error. Array elements can always be followed by a comma no matter what position they're in.

10:36 am
June 18, 2010


Kevin

Admin

posts 2503

8

I'm still not able to reproduce the error with the information you've given. Will need more detail on those other calls if you want me to pursue this.

11:19 am
June 18, 2010


cburtbcit

Member

posts 5

9

Thanks for your persistence Kevin. I'll try to clarify the loop order/calls here. Below is the exact order of all PHP code in my template file. The output of HTML has been omitted to clarify. Thanks again!

get_header();

$some_posts = new WP_Query('category_name=somecategory');

if ($some_posts->have_posts()) {

	while ($some_posts->have_posts()) { 

		$some_posts->the_post();

		post_class('someclass');

		the_ID();

		if (has_post_thumbnail() ) {

			the_post_thumbnail( array( 303, 202 ), array('align' => 'left'));

		}

		the_permalink();

		the_title_attribute();

		the_title();

		if (!empty($post->post_excerpt)) {

			echo this_excerpt();

		} else {

			echo the_content('Read more...');

		}

	}

}

$other_posts = new WP_Query('category_name=othercategory&posts_per_page=1');

if ($other_posts->have_posts() {

	while ($other_posts->have_posts()) {

		$other_posts->the_post();

		the_permalink();

		the_title_attribute();

		the_title();

		the_excerpt();

	}

}

$query = array(
	'category__not_it' => array(5,6),
	'post__in' => get_option('sticky_posts'),
);

$queryObject = new WP_Query($query);

if ($queryObject->have_posts()) {

	$postcount = 1;

	while ($queryObject->have_posts()) {

		$queryObject->the_post();

		if ($postcount > 3) {

			break;

		} else {

			post_class();

			the_ID();

			the_permalink();

			the_title_attribute();

			the_title();

			the_time('F js, Y');

			the_author();

			the_content('Read the rest of this entry »');

			the_tags('Tags: ', ', ', '');

			the_category(', ');

			edit_post_link('Edit', '', '');

			comments_popup_link('No Comment »', '1 Comment »', '% Comments »');

			$postcount++;

		}

	}

} else {

	get_search_form();

}

get_sidebar();

query_posts( array('post__in' => get_option('sticky_posts'), 'category__not_in' => array(5, 6)) );

if (have_posts() && $wp_query->post_count > 3) {

	$postcount = 1;

	while( have_posts() ) {

		the_post();

		if ($postcount < 4 || $postcount > 9) {

			$postcount++;

			continue;

		} else {

			if ($postcount % 2 == 0) {

				if ($postcount == 8) {

					echo 'last';

				}

			}

			post_class();

			the_ID();

			the_title();

			the_content('Read more »');

			if (($postcount - 1) % 2 == 0 || $postcount == $wp_query->post_count) {

				echo "Post Count:" . $wp_query->post_count . " - Post Number: " . $postcount;

			}

		}

		$postcount++;

	}

}

get_footer();

11:24 am
June 18, 2010


Kevin

Admin

posts 2503

10

What's smiley doing there? Maybe he's your problem.

11:45 am
June 18, 2010


Kevin

Admin

posts 2503

11

I plugged this code into my index.php on WP 2.9.2 + RS 1.2.3

Everything appears fine for both logged and unlogged user. I changed made the categoryname arguments valid for my site. The result sets for all four queries look right, with the last one maxing out at postcount = 8.

The only snags I ran into:

  • There is a syntax error (missing close parenth) in if ($other_posts->have_posts() {
  • My WP 2.9.2 didn't have the has_post_thumbnail function defined

1:28 pm
June 18, 2010


cburtbcit

Member

posts 5

12

I'll try to cause the error again and review the output I get more closely. This is peculiar indeed. :D Thanks so much for your assistance. It's great to know that this great plugin has an equally great support forum.


About the Agapetry forum

Currently Online:

15 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1249

Posts: 5659

Members:

There are 1261 members

There are 1 guests


Kevin has made 2503 posts

Top Posters:

metal450 - 178

Ragnar - 108

YikYak - 70

whiteorb - 49

Daisy - 35

Administrator: Kevin | Moderators: Kevin