Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 686 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get current category ID of the active page

#11
Tried above for solutions to find cat ID of a post, but nothing worked, used the following instead:


$obj = get_queried_object();
$c_id = wp_get_post_categories($obj->ID);
Reply

#12
if you need the category ID, you would get it via [get_query_var][1], that is capable of retrieving all publicly queryble variables.

$category_id = get_query_var('cat');
here is an example to get the category name

$category_name = get_query_var('category_name');

and of course the all mighty [get_queried_object][2]

$queried_object = get_queried_object();
that is returning the complete taxonomy term object (when used on a taxonomy-archive page..)


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#13
Here's an efficient method to get category meta data, along with HTML if you want to print it out on the front-end:

```php
<?php

function custom_get_categories() {
$categories = get_the_category();
$uncategorised_id = get_cat_ID('Uncategorized');
$custom_category_link = '';

foreach ($categories as $category) {
if($category->category_parent == $uncategorised_id || $category->cat_ID == $uncategorised_id) {
continue;
}

$custom_category_link = get_category_link($category->cat_ID); ?>

<a href ="<?php echo $custom_category_link ?>">
<?php echo "\n\nCategory ID: " . $category->cat_ID . "\nCategory Name" . $category->name; ?> </a>

<?php
}``
}

?>
```
Reply

#14
I tested all these answers and this is the only one which works on all archive page types including posts page.

$category_id = get_the_category( get_the_ID());
$cat_id = get_category($category_id[0]->term_id);
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through