Which intends to display a list of a specific post type (stores) in the sidebar if a specific custom field is not empty. On single posts that works great - on the main page (home.php) it doesn't - the sidebar widget is empty.

The rest of the sidebar shows - but the specific list is empty on the home page. I took the code snipped from wordpress.org - I haven't tried the other options as, to be honest, my coding skills suck as much as the weather in Chicago.
–
JohnJan 3 '11 at 13:05

1 Answer
1

This is your code converted so it does not use global variables, and thus can't stomp on anything. If this does not work, check your plugins: maybe one of them uses a hook in WP_Query to change the query on the home page? get_posts() gets around that by setting suppress_filters to true, but I don't know whether that disables all hooks.

That is awesome, thanks so much. I am getting this error, though: syntax error, unexpected ';' on line 15
–
JohnJan 3 '11 at 21:36

@John: I forgot a closing paren, it should be esc_attr( get_the_title( $s_post->ID ) ). If you get another syntax error, it helps if you can tell me what's on that line, because we don't start at the same number.
–
Jan FabryJan 3 '11 at 22:30

Same crazy problem - error is fixed but the results still do not show on the main page. The widget is empty, but for the widget title.
–
JohnJan 3 '11 at 22:51

OK quick update. I've been putzing around a bit and this is what I have: I changed $sidebar_posts = get_posts( $args ); into $sidebar_posts = get_posts( array( 'suppress_filters' => true ) ); - and this at least gets a partial output. All results are there, but the content of a second custom field (_simple_fields_fieldGroupID_1_fieldID_9_numInSet_0) isn't showing in the results. It's probably just the way I butchered the query - could you tell me how to construct the existing query with suppress_filters?
–
JohnJan 3 '11 at 23:27

@John: You can add the 'suppress_filters' => true line to the $args array, and it should work. Be sure to place a comma after each line in the array, otherwise you get a syntax error.
–
Jan FabryJan 4 '11 at 8:25