Display all category names for current post in wordpress2019 Community Moderator Electionhow to display all categories in wordpress?Display multiple category name wordpressPHP displaying Wordpress array.WordPress Custom Taxonomy display categoryPHP foreach display country name in API CallHow to get Wordpress posts by category?WordPress: Adding a custom post type taxonomy template in pluginWordpress custom post type with categories archive pagejQuery live search filter - Display 'Nothing Found' message and update WordPress post countWordPress shows only posts from one categoryHow do I return a variable value from each custom post type post in WordPress?Get image post by taxonomy/category wordpress
How to design an organic heat-shield?
When Schnorr signatures are part of Bitcoin will it be possible validate each block with only one signature validation?
Dynamic Linkage of LocatorPane and InputField
Is a piano played in the same way as a harmonium?
Outlet with 3 sets of wires
Does an unused member variable take up memory?
ER diagram relationship node size adjustment
Do I really need to have a scientific explanation for my premise?
What is Tony Stark injecting into himself in Iron Man 3?
Source permutation
Signed and unsigned numbers
Giving a career talk in my old university, how prominently should I tell students my salary?
Are small insurances worth it?
Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?
Can bending moments for a combination of loads on a simple beam, be calculated by adding the individual B.M. of each load?
Why is a very small peak with larger m/z not considered to be the molecular ion?
How to resolve: Reviewer #1 says remove section X vs. Reviewer #2 says expand section X
Gaining more land
What's the 'present simple' form of the word "нашла́" in 3rd person singular female?
How is it possible to drive VGA displays at such high pixel clock frequencies?
MySQL importing CSV files really slow
Should I take out a loan for a friend to invest on my behalf?
What is the population of Romulus in the TNG era?
What sort of fish is this
Display all category names for current post in wordpress
2019 Community Moderator Electionhow to display all categories in wordpress?Display multiple category name wordpressPHP displaying Wordpress array.WordPress Custom Taxonomy display categoryPHP foreach display country name in API CallHow to get Wordpress posts by category?WordPress: Adding a custom post type taxonomy template in pluginWordpress custom post type with categories archive pagejQuery live search filter - Display 'Nothing Found' message and update WordPress post countWordPress shows only posts from one categoryHow do I return a variable value from each custom post type post in WordPress?Get image post by taxonomy/category wordpress
Using this Q&A as a guide, I've assigned multiple categories to my post (of a custom post-type). Trying to display all the assigned categories using this code, which is placed in a separate file entirely, project-clipping.php.
$categories = get_the_category();
$cat_name = $categories[0]->name;
foreach ( $categories as $i => $category )
echo esc_html( $categories[0]->name );
if ( $i < $count - 1 )
echo $separator;
It works fine for the first category, but thereafter spits out a notice: Undefined variable: count in.... This occurs thrice, twice, etc. depending on the number of categories assigned to the respective post.
I've tried solving this by placing it in the loop itself, rather than an external file. Does not work.
I've also looked at this but it returns all the categories of the post-type, not the post.
Thank you.
php wordpress
New contributor
Sai sahitya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Using this Q&A as a guide, I've assigned multiple categories to my post (of a custom post-type). Trying to display all the assigned categories using this code, which is placed in a separate file entirely, project-clipping.php.
$categories = get_the_category();
$cat_name = $categories[0]->name;
foreach ( $categories as $i => $category )
echo esc_html( $categories[0]->name );
if ( $i < $count - 1 )
echo $separator;
It works fine for the first category, but thereafter spits out a notice: Undefined variable: count in.... This occurs thrice, twice, etc. depending on the number of categories assigned to the respective post.
I've tried solving this by placing it in the loop itself, rather than an external file. Does not work.
I've also looked at this but it returns all the categories of the post-type, not the post.
Thank you.
php wordpress
New contributor
Sai sahitya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
you didnt define $count variable anywhere else, first define, it seems the variable holds the count of total catergories
– Vidya L
Mar 7 at 5:30
Also are you using custom taxonomy?
– Vidya L
Mar 7 at 5:47
No, I'm not using custom taxonomy, but am a custom post-type.
– Sai sahitya
Mar 7 at 5:54
How can I define the$countvariable so that it holds the count of total categories?
– Sai sahitya
Mar 7 at 5:55
add a comment |
Using this Q&A as a guide, I've assigned multiple categories to my post (of a custom post-type). Trying to display all the assigned categories using this code, which is placed in a separate file entirely, project-clipping.php.
$categories = get_the_category();
$cat_name = $categories[0]->name;
foreach ( $categories as $i => $category )
echo esc_html( $categories[0]->name );
if ( $i < $count - 1 )
echo $separator;
It works fine for the first category, but thereafter spits out a notice: Undefined variable: count in.... This occurs thrice, twice, etc. depending on the number of categories assigned to the respective post.
I've tried solving this by placing it in the loop itself, rather than an external file. Does not work.
I've also looked at this but it returns all the categories of the post-type, not the post.
Thank you.
php wordpress
New contributor
Sai sahitya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Using this Q&A as a guide, I've assigned multiple categories to my post (of a custom post-type). Trying to display all the assigned categories using this code, which is placed in a separate file entirely, project-clipping.php.
$categories = get_the_category();
$cat_name = $categories[0]->name;
foreach ( $categories as $i => $category )
echo esc_html( $categories[0]->name );
if ( $i < $count - 1 )
echo $separator;
It works fine for the first category, but thereafter spits out a notice: Undefined variable: count in.... This occurs thrice, twice, etc. depending on the number of categories assigned to the respective post.
I've tried solving this by placing it in the loop itself, rather than an external file. Does not work.
I've also looked at this but it returns all the categories of the post-type, not the post.
Thank you.
php wordpress
php wordpress
New contributor
Sai sahitya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Sai sahitya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Sai sahitya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Mar 7 at 4:47
Sai sahityaSai sahitya
31
31
New contributor
Sai sahitya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Sai sahitya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Sai sahitya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
you didnt define $count variable anywhere else, first define, it seems the variable holds the count of total catergories
– Vidya L
Mar 7 at 5:30
Also are you using custom taxonomy?
– Vidya L
Mar 7 at 5:47
No, I'm not using custom taxonomy, but am a custom post-type.
– Sai sahitya
Mar 7 at 5:54
How can I define the$countvariable so that it holds the count of total categories?
– Sai sahitya
Mar 7 at 5:55
add a comment |
1
you didnt define $count variable anywhere else, first define, it seems the variable holds the count of total catergories
– Vidya L
Mar 7 at 5:30
Also are you using custom taxonomy?
– Vidya L
Mar 7 at 5:47
No, I'm not using custom taxonomy, but am a custom post-type.
– Sai sahitya
Mar 7 at 5:54
How can I define the$countvariable so that it holds the count of total categories?
– Sai sahitya
Mar 7 at 5:55
1
1
you didnt define $count variable anywhere else, first define, it seems the variable holds the count of total catergories
– Vidya L
Mar 7 at 5:30
you didnt define $count variable anywhere else, first define, it seems the variable holds the count of total catergories
– Vidya L
Mar 7 at 5:30
Also are you using custom taxonomy?
– Vidya L
Mar 7 at 5:47
Also are you using custom taxonomy?
– Vidya L
Mar 7 at 5:47
No, I'm not using custom taxonomy, but am a custom post-type.
– Sai sahitya
Mar 7 at 5:54
No, I'm not using custom taxonomy, but am a custom post-type.
– Sai sahitya
Mar 7 at 5:54
How can I define the
$count variable so that it holds the count of total categories?– Sai sahitya
Mar 7 at 5:55
How can I define the
$count variable so that it holds the count of total categories?– Sai sahitya
Mar 7 at 5:55
add a comment |
1 Answer
1
active
oldest
votes
You didn't define count and separator variable it seems, try like this, change separator variable as per your need.
$categories = get_the_category( get_the_ID() ) // if you are using custom taxonomy replace with get_the_terms( get_the_ID(), 'your-taxonomy');
$separator = '|'; // define separator variable
$count = count($categories); // define count
if ( ! empty( $categories ) ) // check if not empty
foreach ( $categories as $i=>$category )
echo esc_html( $category->name );
if ( $i < $count - 1 )
echo $separator;
Thank you; this almost works; just that the same category is printed repeatedly
– Sai sahitya
Mar 7 at 6:06
Thank you; copy-pasting your code resolved the issue. Why it is, I'll analyze.
– Sai sahitya
Mar 7 at 6:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sai sahitya is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036278%2fdisplay-all-category-names-for-current-post-in-wordpress%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You didn't define count and separator variable it seems, try like this, change separator variable as per your need.
$categories = get_the_category( get_the_ID() ) // if you are using custom taxonomy replace with get_the_terms( get_the_ID(), 'your-taxonomy');
$separator = '|'; // define separator variable
$count = count($categories); // define count
if ( ! empty( $categories ) ) // check if not empty
foreach ( $categories as $i=>$category )
echo esc_html( $category->name );
if ( $i < $count - 1 )
echo $separator;
Thank you; this almost works; just that the same category is printed repeatedly
– Sai sahitya
Mar 7 at 6:06
Thank you; copy-pasting your code resolved the issue. Why it is, I'll analyze.
– Sai sahitya
Mar 7 at 6:11
add a comment |
You didn't define count and separator variable it seems, try like this, change separator variable as per your need.
$categories = get_the_category( get_the_ID() ) // if you are using custom taxonomy replace with get_the_terms( get_the_ID(), 'your-taxonomy');
$separator = '|'; // define separator variable
$count = count($categories); // define count
if ( ! empty( $categories ) ) // check if not empty
foreach ( $categories as $i=>$category )
echo esc_html( $category->name );
if ( $i < $count - 1 )
echo $separator;
Thank you; this almost works; just that the same category is printed repeatedly
– Sai sahitya
Mar 7 at 6:06
Thank you; copy-pasting your code resolved the issue. Why it is, I'll analyze.
– Sai sahitya
Mar 7 at 6:11
add a comment |
You didn't define count and separator variable it seems, try like this, change separator variable as per your need.
$categories = get_the_category( get_the_ID() ) // if you are using custom taxonomy replace with get_the_terms( get_the_ID(), 'your-taxonomy');
$separator = '|'; // define separator variable
$count = count($categories); // define count
if ( ! empty( $categories ) ) // check if not empty
foreach ( $categories as $i=>$category )
echo esc_html( $category->name );
if ( $i < $count - 1 )
echo $separator;
You didn't define count and separator variable it seems, try like this, change separator variable as per your need.
$categories = get_the_category( get_the_ID() ) // if you are using custom taxonomy replace with get_the_terms( get_the_ID(), 'your-taxonomy');
$separator = '|'; // define separator variable
$count = count($categories); // define count
if ( ! empty( $categories ) ) // check if not empty
foreach ( $categories as $i=>$category )
echo esc_html( $category->name );
if ( $i < $count - 1 )
echo $separator;
answered Mar 7 at 6:01
Vidya LVidya L
1,70941935
1,70941935
Thank you; this almost works; just that the same category is printed repeatedly
– Sai sahitya
Mar 7 at 6:06
Thank you; copy-pasting your code resolved the issue. Why it is, I'll analyze.
– Sai sahitya
Mar 7 at 6:11
add a comment |
Thank you; this almost works; just that the same category is printed repeatedly
– Sai sahitya
Mar 7 at 6:06
Thank you; copy-pasting your code resolved the issue. Why it is, I'll analyze.
– Sai sahitya
Mar 7 at 6:11
Thank you; this almost works; just that the same category is printed repeatedly
– Sai sahitya
Mar 7 at 6:06
Thank you; this almost works; just that the same category is printed repeatedly
– Sai sahitya
Mar 7 at 6:06
Thank you; copy-pasting your code resolved the issue. Why it is, I'll analyze.
– Sai sahitya
Mar 7 at 6:11
Thank you; copy-pasting your code resolved the issue. Why it is, I'll analyze.
– Sai sahitya
Mar 7 at 6:11
add a comment |
Sai sahitya is a new contributor. Be nice, and check out our Code of Conduct.
Sai sahitya is a new contributor. Be nice, and check out our Code of Conduct.
Sai sahitya is a new contributor. Be nice, and check out our Code of Conduct.
Sai sahitya is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036278%2fdisplay-all-category-names-for-current-post-in-wordpress%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
you didnt define $count variable anywhere else, first define, it seems the variable holds the count of total catergories
– Vidya L
Mar 7 at 5:30
Also are you using custom taxonomy?
– Vidya L
Mar 7 at 5:47
No, I'm not using custom taxonomy, but am a custom post-type.
– Sai sahitya
Mar 7 at 5:54
How can I define the
$countvariable so that it holds the count of total categories?– Sai sahitya
Mar 7 at 5:55