Site logo

Archived topic

How to set an Element location to Child of a Parent Page

3 replies · Started by Tim on April 18, 2020

Viewing posts 1–4 of 4

Hello

Previously I have created custom fields for posts with ACF setting their location as:
"Post Category" "is equal to" "CategoryName".

I am then able to create an Element hook to Display Location as:
"Post Category" "is equal to" "CategoryName".

Good.

However, with Pages I create custom fields where "Page Parent" "is equal to" "ParentPageName".

But I do not see an equivalent Display Location for my hook, only
"Page" "is equal to" "SpecificPageName"

Am I missing an option ?

Hi David

Look forward to that page relationships added to Elements.

Thank you for pointing out that thread.

Turns out this post was the one I needed as it includes and array of Parent Pages:
https://generatepress.com/forums/topic/conditionally-display-hook-on-sub-page-of-parent/#post-1092863

add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
  global $post;

  if ( $element_id===3106 && 
       ( is_page(array(1291,1326)) || 
         is_page() && $post->post_parent===1291 || 
         is_page() && $post->post_parent===1326 
       ) 
     ) {
     $display = true;
  }	
  return $display;
}, 10, 2 );

What does the }, 10, 2 ); part represent ?

This archived topic is closed to new replies.