ewels / CPT-Bootstrap-Carousel

WordPress plugin which generates a custom post type for choosing images and content. Outputs Bootstrap Image Carousel (slider) HTML from a shortcode.
http://wordpress.org/plugins/cpt-bootstrap-carousel/
GNU General Public License v2.0
51 stars 36 forks source link

Get the parent #77

Closed sajadghawami closed 8 years ago

sajadghawami commented 8 years ago

Hey there,

i am trying to customize this plugin a little bit.

How would i get the parent?

$atts['category'];

Shows the current category, but i am trying to get the parent-category!

thanks for your help.

ewels commented 8 years ago

Hi @leakingminds,

Check out the WordPress codex - I think get_category_parents should do what you want.

Cheers,

Phil

sajadghawami commented 8 years ago

Hey @ewels

thanks for the fast reply, but that gives me the parent category of the page, and not the one i gave it in the slider options!

Thanks, Sajad

ewels commented 8 years ago

Really? I thought it gave you the parent categories of whatever category id you pass to it? So you could pass it the category variable that you mention above:

echo get_category_parents( $atts['category'] );

I haven't tried it though, so apologies if I'm wrong about this.

sajadghawami commented 8 years ago

You were right, the solutions works.

But i had to put it before the loop in

function cptbc_frontend($atts)

so basically i did this:

$page_id = get_the_ID();
$parent_page_id = wp_get_post_parent_id($page_id);

That works now!

thanks a bunch for your effort :)