#24714 closed defect (bug) (fixed)
get_template_part : !empty instead of isset ?
| Reported by: | tivnet | Owned by: | nacin |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.6 |
| Component: | Template | Version: | 3.0 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | Focuses: |
Description
With a call like this one:
get_template_part( 'content', get_post_format() );
get_post_format() may return false, and then the following condition does not do what it should:
if ( isset($name) )
$templates[] = "{$slug}-{$name}.php";
and tries to load content-.php
Using !empty instead of isset should work better.
Attachments (2)
Change History (9)
#3
@
13 years ago
Actually, '0' is probably valid. Think get_template_part( 'something', get_query_var( 'paged' ) ) where an integer might be valid. Pagination generally starts with 1, but you get the idea.
False and null, cast to strings, equals ''. That's what is happening anyway (as in, if you pass an array, we'll go looking for "something-Array.php"), so let's be explicit and add a check.
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Could probably just be
if ( $name ), as we know the variable is set.