- This topic has 19 replies, 3 voices, and was last updated 1 month ago by
David.
-
AuthorPosts
-
January 16, 2021 at 8:36 pm #1621926
Takeru
Element ID
/wp-admin/post.php?post=553&action=edit
Author ID
/wp-admin/user-edit.php?user_id=2
Add a filter
add_filter( 'generate_hook_element_display', function( $display, $element_id ) { $author_id = get_post_field( 'post_author', get_the_ID() ); if ( 553 === $element_id && '2' == $author_id ) { $display = true; } return $display; } );
I added the above code to the Code Snippets plugin, but it did not work.
Is there something wrong with the above code?
January 17, 2021 at 5:58 am #1622198David
StaffCustomer SupportHi there,
what Element are you trying to display? That is specifically for the Hook Element, there are other filters for Header Element, Layout Element and Block Element.
If it is the Hook Element – does it work if you do not use the filter and just set the Display Location ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/January 17, 2021 at 11:59 am #1622715Takeru
I want to create and display a different author box for each author below the content using GenerateBlocks.
So, if I set the Display Location without using a filter, it will show up in all the author’s posts.
January 18, 2021 at 6:40 am #1623422David
StaffCustomer SupportYes, i understand – just need to check whether the Hooked element is working correctly by giving it a specific display rule. If it does work then we can look at why that filter is not working.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/January 18, 2021 at 12:07 pm #1624125Takeru
I added the code using the following page as a reference, changing only the ID, but it doesn’t work.
https://generatepress.com/forums/topic/add-element-to-posts-by-specific-author/
Which points should I check?
January 19, 2021 at 1:50 am #1624616David
StaffCustomer SupportWhat Element is it you’re using ? Is it a Block Element ? If so instead of:
generate_hook_element_display
you use:
generate_block_element_display
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/January 19, 2021 at 12:23 pm #1625448Takeru
I use the Block Element.
I finally added the following code as you suggested, but I got an error.
add_filter( 'generate_block_element_display', function( $display, $element_id ) { $author_id = get_post_field( 'post_author', get_the_ID() ); if ( 553 === $element_id && '2' == $author_id ) { $display = true; } return $display; } );
January 19, 2021 at 10:32 pm #1625824Elvin
StaffCustomer SupportHi,
Can you provide the error you’re getting so we could have an idea?
( 553 === $element_id && '2' == $author_id )
on this line, can you try changing'2'
to just2
.Let us know.
A wise man once said:
"Have you cleared your cache?"January 19, 2021 at 10:43 pm #1625827Takeru
Thank you.
However, it still doesn’t seem to work.The error seems to have security information in it and I am not sure which part to tell you.
What part of the error should I tell you about?
For example, is it a url like the following?/wp-includes/class-wp-hook.php on line 289 and exactly
/wp-content/plugins/gp-premium/elements/elements.php(74): GeneratePress_Block_Element->__construct(97)
The following errors are shown in bold.
/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()'d code on line 1
January 19, 2021 at 10:52 pm #1625837Elvin
StaffCustomer SupportYou can use the private information text field for sensitive information so only the support members could see it.
A wise man once said:
"Have you cleared your cache?"January 19, 2021 at 10:57 pm #1625840Takeru
Thank you.
Now, I will send you the error after registering the following code.
add_filter( 'generate_block_element_display', function( $display, $element_id ) { $author_id = get_post_field( 'post_author', get_the_ID() ); if ( 553 === $element_id && 2 == $author_id ) { $display = true; } return $display; } );
January 19, 2021 at 11:39 pm #1625871Elvin
StaffCustomer SupportTry this instead:
add_filter( 'generate_block_element_display', function( $display, $element_id ) { $author_id = get_post_field( 'post_author', get_the_ID() ); if ( 553 === $element_id && '2' == $author_id ) { $display = true; } else if ( 553 === $element_id && '2' != $author_id ){ $display = false; } return $display; }, 15, 2 );
Are you applying it on a post list loop? If so, I don’t think this’ll work.
But if it’s on single posts page, I can confirm that this particular snippet will work.
A wise man once said:
"Have you cleared your cache?"January 19, 2021 at 11:44 pm #1625875Takeru
It worked!
I greatly appreciate the support staff’s kindness and patience!January 19, 2021 at 11:47 pm #1625877Elvin
StaffCustomer SupportIt worked!
I greatly appreciate the support staff’s kindness and patience!Nice one. Glad it worked for you. 🙂
A wise man once said:
"Have you cleared your cache?"January 20, 2021 at 4:09 pm #1627051Takeru
On the author page, the block element I created goes under each post, is there any way to work around this?
-
AuthorPosts
- You must be logged in to reply to this topic.