Show content if page is a grandchild of top level page
Check how many ancestors the page has via get_post_ancestors: // grandchild pages will have two or more ancestors if( 2 <= count( get_post_ancestors( $post->ID ) ) ){ echo ‘grandchild page’; }
Check how many ancestors the page has via get_post_ancestors: // grandchild pages will have two or more ancestors if( 2 <= count( get_post_ancestors( $post->ID ) ) ){ echo ‘grandchild page’; }
It turns out that the first hook function, which contained a query needed a reset. Adding wp_reset_query(); after the initial query has fixed the issue.
There is no “default” post format type, though internally in core, a post that has no post format assigned is usually referred to as standard. So, your first conditional will return false using post-format-normal because there is no such post format – but would still return false using post-format-standard. You could reverse the conditional, and … Read more
wp_get_post_tags() returns an array. You cannot echo an array or all you get is “Array”. If this is the ados_setKeywords you mean, then you need to feed it a comma delimited string, not an array. ados_setKeywords(implode(‘, ‘,wp_get_post_tags()));
Cheers guy’s this helped me a lot, I used the below which works great, any improvements appreciated. <?php $cat1 = array(‘category1’, ‘category2’); if( has_term( $cat1, ‘my_custom_post_type’ ) ) { //do something } else { //do somthing else}?>
One alternative is simply not to display the comment field if the current user isn’t logged in, using is_user_logged_in(). For example, inside your comments template: <?php comment_form( $args ); ?> Just wrap that in a conditional: <?php // Don’t output the comment form if CPT and user isn’t logged in if ( ‘debate’ != get_post_type() … Read more
To redirect after 3 days gone after publication, hook into template_redirect, check if is a singular cpt view, check the date and compare to current time and redirect if needed. In the 3 days time frame, check if stats is is the query vars and if so redirect to post page. add_action(‘template_redirect’, ‘check_the_date_for_stats’); function check_the_date_for_stats() … Read more
I can’t see a problem with your if-else-statement, so I’m thinking the problem origins somewhere else. You say you get no errors, I guess you have debugging enabled. Besides, did you debug and inspect – var_dump or print_r it – the $wp_query object, to see if it is really empty, has no posts. Another thing, … Read more
Your solution won’t work, because $ep_category->category_parent is ID (integer) and not slug (string). So this comparison doesn’t make any sense… 😉 One way to do this would be this function (from Codex): if ( ! function_exists( ‘post_is_in_descendant_category’ ) ) { function post_is_in_descendant_category( $cats, $_post = null ) { foreach ( (array) $cats as $cat ) … Read more
The Core function for checking whether a user is logged in is is_user_logged_in(). You should use that if at all possible. WordPress does not use sessions at all, by default, and never has so far as I can remember. When I try var_dump($_SESSION); I get an “Undefined variable” Notice exactly as I expected. I haven’t … Read more