• Resolved hedgomatic

    (@hedgomatic)


    I’m creating a publication plugin & theme that organizes posts into volumes and issues, like a magazine or newspaper.

    My plugin sets both an active issue, and an “upcoming” issue that is only viewable by the admin. All posts receive several categories: “Live” (aka: publicly viewable), “Submitted” (offline, admin-viewable) and the volume and issue in the following format: Volume#_Issue#

    So, in my admin logic, I’m querying for the next volume and issue options from my plugin:

    if (current_user_can(‘manage_options’)) {
    $Volume = get_option( $opt_nextVolume_name );
    $Issue = get_option( $opt_nextIssue_name );

    and then putting them together:

    $VolumeAndIssue = ‘Volume’.$Volume.’_Issue’.$Issue;

    Then I look for posts with this category:

    if (is_home()) { query_posts(‘category_name=’.$VolumeAndIssue); } else { query_posts(‘category_name=Live’); }

    However if(have_posts()) returns false, and query_posts returns an empty array.

    Spitting out the value of $VolumeAndIssue, I see that it’s set to Volume1_Issue3 (which is correct)

    I have a single post with some lorem ipsum text marked with this category.

    I’ve double-checked for any typos or case-sensitive errors.

    Any advice on how I can better debug the problem?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter hedgomatic

    (@hedgomatic)

    here’s a screeshot of the post that should be pulled by the logic above.

    Here’s the relevant code all in one chunk:

    <?php
    if (current_user_can('manage_options')) {
    	$is_admin = true;
    	$Volume = get_option( $opt_nextVolume_name );
    	$Issue = get_option( $opt_nextIssue_name );
    	$VolumeAndIssue = 'Volume'.$Volume.'_Issue'.$Issue;
    	if (is_home()) { query_posts('category_name='.$VolumeAndIssue); } else { query_posts('category_name=Live'); }
    } else {
    // not logged in query, etc
    }
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    		<? /*** CUSTOM THEME OPTIONS FOR THE ISSUE ***/ ?>
    		<?php include(TEMPLATEPATH.'/'.$VolumeAndIssue.'.php'); ?>
    		<?php the_content(__('(more...)')); ?>
    <?php endwhile; else: ?>
    	<p><?php _e("Sorry, we couldn't find what you were looking for."); ?></p>
    <?php endif; ?>

    Returns:

    “Sorry, we couldn’t find what you were looking for.”

    Update: If I remove the query_post(), thereby getting all my published posts, and then try:

    <? if(is_category($VolumeAndIssue)) { echo 'test'; } ?>

    returns nothing. So for some reason it considers the post not to be assigned to this category. The plot thins.

    Running get_the_category has gotten me really stumped. Consider this:

    <?php
    echo '<b>Categories: </b>';
    foreach((get_the_category()) as $category) {
        echo $category->cat_name . ' ';
    }
    echo '<BR /><B>VolumeAndIssue variable:</b> '.$VolumeAndIssue;
    ?>

    returns this.

    I then removed the ‘offline’ tag, just in case there was an issue with that being the first category. No change.

    Update 2:

    Something’s not right here.

    foreach((get_the_category()) as $category) {
        echo $category->cat_name . ' ';
    if(is_category($category->cat_name)) { echo '<br />debug:'.$category->cat_name.'<br />'; }	else { echo '<br />can\'t find category<br />'; }
    }

    Unless I’m confused as to how this conditional works, it should always be able to find the category. However it returns false having not found the category it just found. Huh?!?

    Thread Starter hedgomatic

    (@hedgomatic)

    Fixed:

    While I was indeed confused on what is_category() does, I did manage to figure out that the problem is a bug and/or limitation in WordPress: it doesn’t accept underscore (_) characters in category names.

    Thread Starter hedgomatic

    (@hedgomatic)

    after looking at bug 11121, I gathered that sanitize_title() in formating.php is responsible for cleaning the category names.

    Nothing I saw there or in apply_filters() would create the issue however. I’ve no mind to edit the core of course, but it’d be nice to know if there’s a possible override for this.

    Thread Starter hedgomatic

    (@hedgomatic)

    dashes didn’t seem to work either until I realized I shouldn’t use an alternate name for the slug.

    Naming my slug “Volume1-Issue3”

    and then doing:

    query_posts(‘category_name=Volume1-Issue3’);

    works.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘query_posts not pulling category_name.’ is closed to new replies.