hi—
using toolset i've created a taxonomy to categorize my posts called "news-categories". there are two parent categories that allow me to direct content to different pages—posts categorized as 'news' display on one page while those categorized as 'student news' display on another.
for my 'student news' single posts i would like to include the name of the post author, but not on single pages for 'news'.
i added the following code to alter the info attribution, but of course this effects all my single posts:
add_filter( 'genesis_post_info', 'genesischild_post_info' );
function genesischild_post_info($post_info) {
if (!is_page()) {
$post_info = 'by [acf field="author"] | [post_date] ';
return $post_info;
}
}
how can i target one parent category and not the other based on which toolset taxonomy they belong to?
Hello,
It needs custom codes, here are my suggestions:
In your PHP code, you can get all terms assigned to current post with function wp_get_object_terms()
https://codex.wordpress.org/Function_Reference/wp_get_object_terms
Then use function term_is_ancestor_of() to check if term "student news" is each term's ancestor
https://codex.wordpress.org/Function_Reference/term_is_ancestor_of
If the condition is satisfied, then output what you want.
hi luo—
i need some more help here, i dont know php very well. it seems like the pages you're pointing me to are in the right direction but i dont know how exactly to make sense of them, to target the taxonomy i've created in toolset.
from the original code i sent over i know the line
is the one that needs to be changed. it needs to be looking for my 'student-news' category slug (ID=31) within my 'news-categories' taxonomy.
if i take what's in the codex and alter it to my situation, below is what i come up with, however it crashes my site. what am i doing wrong?
revised code
// student post pages include author
add_filter( 'genesis_post_info', 'genesischild_post_info' );
function genesischild_post_info($post_info) {
if (term_is_ancestor_of(31, $term, 'news-categories') or is_term(31, 'news-categories')): {
$post_info = 'by [acf field="author"] | [post_date] ';
return $post_info;
}
}
Since it is a custom PHP codes problem, please provide a test site with the same problem, and fill below private message box with credentials and FTP access, also point out the problem page URL and where I can edit your PHP codes, I need a live website to test and debug.
If you are going to setup the condition on if current post has term "open-line-post" (ID=30), you can use wordpress function has_term to check it easily, for example, modify your PHP codes as below:
add_filter( 'genesis_post_info', 'genesischild_post_info' );
function genesischild_post_info($post_info) {
if( is_single() && has_term( 'open-line-post', 'news-categories' ) ) {
$post_info = 'by [acf field="author"] | [post_date] ';
}
return $post_info;
}
More help:
https://developer.wordpress.org/reference/functions/has_term/
The given terms are checked against the post’s terms’ term_ids, names and slugs.
I can login your website, but can not edit php codes in dynamik > custom > functions, it does not save any change. I see some JS errors when click the save button.
And you did not point out where and how can I see the result in front-end, so I can not test and debug the codes in your website.