Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1030081

    Hi,

    I have kinda a unique setup that I need for page title for my CPT. I currently have three levels. Grandparent > Parent > Child. Here is what im trying to do.

    If the current page is three levels down the title needs to be pulled from the grandparent. If it’s two level down it needs to pull from the parent.

    For example

    Page 1 is working correctly. This page is pulling in the parent page title. Good stuff!

    Page 2 is not. This page need to have the title of Water Environmental Resources because its three levels down. That would be the grandparent title.

    Hope this makes sense. Here is my current code to change CPT title. I know its only pulling in parent pages im just not even sure where to start things on how i need them to work.

    
    add_filter('avf_title_args', 'fix_single_post_title', 10, 2);
    function fix_single_post_title($args,$id) {
        if ( is_singular('solutions') ) { // 24 being Page ID of the blog index
            $args['title'] = get_the_title( wp_get_post_parent_id( get_the_ID() ) );
        } elseif ( is_singular('contracts') ) {
        	$args['title'] = 'Contract Vehicles';
        } 
    
        return $args;
    }
    
    #1030585

    Because I know you will ask for it.

    #1031093

    Hi,

    Thank you for using Enfold.

    A quick search led me to this thread:

    // https://wordpress.stackexchange.com/questions/279445/cannot-get-grandparent-object

    So you need to get the current post id, check if a parent page is set, get the id of that parent page, check if the current post parent’s post_parent value is set and then get the grand parent page. Just copy the conditional logic from that thread and you’re good to go.

    Best regards,
    Ismael

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.