WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#6741 closed defect (bug) (worksforme)

in_category not working in WP 2.5 - ignores category id/name

Reported by: TrishaM Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Template Keywords:
Focuses: Cc:

Description

Used the following code as suggested in the Codex for in_category, however, in all cases regardless of the actual category ID that the post has assigned to it, the second include-file is being served.

`<?php

$post = $wp_query->post;

if (in_category(16)) {

include(TEMPLATEPATH . '/single-cat-16.php');
}

else {

include(TEMPLATEPATH . '/singleproduct.php');
}

?>`

Change History (3)

comment:1 follow-up: Otto426 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Tested and that does work if you add global $post to the front of it, to ensure you're modifying the right $post variable.

The codex probably needs to be clarified on this point.

comment:2 in reply to: ↑ 1 TrishaM6 years ago

Replying to Otto42:

Tested and that does work if you add global $post to the front of it, to ensure you're modifying the right $post variable.

The codex probably needs to be clarified on this point.

Can you please clarify "add global $post to the front of it" - perhaps an example? The Codex is not changed yet and until it is I need to know how to make this "workforme".....thx

comment:3 Otto426 years ago

  • Cc TrishaM removed
  • Keywords in_category removed
  • Milestone 2.7 deleted
  • Version 2.5 deleted

I updated the codex and replied in your forum support thread. That method of accessing loop variables outside the loop is actually pretty poor, so I explained a better one instead.

Note: See TracTickets for help on using tickets.