retriving attachement category
Topics related to RedWaves lite theme goes here.

ahmed

New Member Rank
Posts: 1
Joined: Mon Feb 05, 2018 11:08 pm
Display Name: ahmed

retriving attachement category

linkPost by Ahmed Abdelbaky » Mon Feb 05, 2018 11:46 pm

good day admin
I have add category for the attachment by adding the following code to function.php
// add categories for attachments
function add_categories_for_attachments() {
    register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init' , 'add_categories_for_attachments' );
?>
the problem that when i try to show the attachment category it give me nothing ( i mean nothing to show up when i try to retrive attachment assigin in certain attachmment category ).
I need to show up ( retrive ) the attachment category ( as post category )
thank you
User avatar
Asmi Khalil

Site Admin Rank
Posts: 781
Joined: Fri Jun 26, 2015 7:13 am
Display Name: Asmi Khalil
Location: Tunisia

Re: retriving attachement category

linkPost by admin » Fri Feb 09, 2018 10:28 pm

Hi Ahmed,

Thanks for joining our forum :D
Your code should work just fine. Maybe the ?> at the end is what causing the error. Remove it.
As a rule of thumb, never close your PHP files unless there is a HTML code after the PHP code and always prefix your PHP functions.
This is a slightly better version of your code:
add_action( 'init' , 'redwaves_add_categories_for_attachments' );
if ( !function_exists( 'redwaves_add_categories_for_attachments' ) ) {
    function redwaves_add_categories_for_attachments() {
        register_taxonomy_for_object_type( 'category', 'attachment' );
    }
}
I think there is a world market for maybe five computers. - IBM chairman Thomas Watson, 1943

Who is online

Users browsing this forum: No registered users and 1 guest

It is currently Wed Oct 16, 2019 2:48 am