Announcement

Collapse
No announcement yet.

PHP: targeting multiple terms?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP: targeting multiple terms?

    hiya—

    i've got two "blogs" on my site pulling posts from different categories. on one blog (student-news) i would like to include the name of the post author and the date. on the other blog (news), i'd just like to include the date. i've can figure out the php to get either one of these options to work but not both (i have figured out that if i switch the order in custom functions, the news post code will work and not the student news code... so there is something with the order, and maybe the fact that im using the same hook?)

    using dynamik for a few years now i've become somewhat familiar with php, i know enough to kind of figure out what needs to go where, but not enough to understand what i need to do to get both snippets to fire at the same time—anyone able to spot what im doing wrong here?


    here is an example of the code working for the student blog:
    https://prisonuniversityproject.org/2aug/?p=1431


    but here you can see no date for a news post:
    https://prisonuniversityproject.org/2aug/?p=1516



    and here's my php:

    //* Customize post info news posts

    add_filter( 'genesis_post_info', 'da_post_info_news' );

    function da_post_info_news($post_info) {

    if(has_term( 'news-post', 'news-category' ) ) {

    $post_info = '[post_date]';

    return $post_info;

    }

    }




    //* Customize post info for open line posts (student news)

    add_filter( 'genesis_post_info', 'da_post_info_openline' );

    function da_post_info_openline($post_info) {

    if(has_term( 'open-line-post', 'news-category' ) ) {

    $post_info = 'by [acf field="author"] | [post_date] ';

    return $post_info;

    }

    }

  • #2
    Sorry, seeing we can´t access the frontend (seems protected), and we don´t really have insight regarding your terms and categories and if they´re correct (backend), it´s hard to help here. You might want to consider to take this to the support team, it might make more sense in this case.

    (Why is it you use news-category in both snippets? Probably, if these are different pages, you could address the page-ID in your code?)
    Maybe, if these are different categories - a different approach? https://www.wpstuffs.com/remove-date...sis-framework/

    Comment


    • #3
      oof, sorry about the protected pages. that said, you gave me *just* the nudge i needed to target both pages with that link, so THANKS!!! it was that last little bit containing the "else" code. really appreciate the link.

      // Customise post info news posts
      add_filter( 'genesis_post_info', 'da_post_info' );
      function da_post_info($post_info) {
      if(has_term( 'open-line-post', 'news-category' ) ) {
      $post_info = 'by [acf field="author"] | [post_date] ';
      }
      else {
      $post_info = '[post_date]';
      }
      return $post_info;
      }

      Comment


      • SiGa
        SiGa commented
        Editing a comment
        Really glad to hear you got a working solution now!
    Working...
    X