• I have a filter to change the title of posts. I used get_post_type() to apply it only to post types. However, this gets the post type of the current page, not the page whose title I want to change.

    This is a problem on the front page, where I have featured pages (not post type) and recent posts (is post types). It’s also a problem on the menu, which links to pages that aren’t post type. But if, for example, I’m on a page of type post, the titles of the menu pages will also be altered.

    How do I set the conditional to get the post type of the target post, and not the page that I’m currently on?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I used get_post_type() to apply it only to post types. However, this gets the post type of the current page, not the page whose title I want to change.

    what is the exact code you are using?

    what theme are you using?

    https://codex.wordpress.org/Function_Reference/get_post_type

    as you see from the Codex docu, you can use an ID in the code.

    Thread Starter dickli

    (@dickli)

    Hi Michael,

    Code is below. Since it will be referring to several pages and not just one, what would the post_id argument be to make the snippet dynamic?

    add_filter(‘get_the_title’, ‘aggregate_title’, 10, 2);

    function aggregate_title ($title) {

    if (‘post’ == get_post_type()) {

    $my_title = get_field(‘day’);
    $new_title = ‘Day ‘ . $my_title . ‘: ‘ . $title;
    return $new_title;

    } else {

    return $title;

    }
    }

    Thread Starter dickli

    (@dickli)

    Theme is Customizr

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to get post type of ANOTHER post’ is closed to new replies.