[Resolved] How to set an Element location to Child of a Parent Page

Home Forums Support [Resolved] How to set an Element location to Child of a Parent Page

Home Forums Support How to set an Element location to Child of a Parent Page

  • This topic has 3 replies, 2 voices, and was last updated 4 years ago by David.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1243889
    Tim

    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 ?

    #1244106
    David
    Staff
    Customer Support

    Hi there,

    nope not missing an option – parent relationships are something we are looking into for display rules and maybe a future option. For now it requires a filter like the one shared by this user:

    https://generatepress.com/forums/topic/conditionally-display-hook-on-sub-page-of-parent/#post-760775

    #1244902
    Tim

    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 ?

    #1245046
    David
    Staff
    Customer Support

    The Priority and the number of arguments

    https://developer.wordpress.org/reference/functions/add_filter/

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