- This topic has 29 replies, 3 voices, and was last updated 3 years, 8 months ago by Randy.
-
AuthorPosts
-
August 7, 2020 at 12:16 pm #1391981Randy
To clarify my question, at the moment, I think I need to find out where I can find the element IDs. I have both author boxes active, but both are showing up on every page. The PHP doesn’t seem to be working yet. I’ve tried a couple different things for the IDs, but apparently, I have gotten it right yet.
Thanks!
August 7, 2020 at 1:01 pm #1392061TomLead DeveloperLead DeveloperHi there,
When editing the Element in the Dashboard, you can see the ID in the URL. It should be the only number.
Let us know π
August 7, 2020 at 2:28 pm #1392132RandyHmmm. That’s what I thought. As far as I know, then, the code is correct. But, they’re both being inserted after the content, as here.
Thanks!
August 8, 2020 at 4:12 am #1392683DavidStaffCustomer SupportAside of the ID numbers being correct we also have the
is_author()
condition which can use ID, Nice Name and Nickname. These examples explain then well:https://developer.wordpress.org/reference/functions/is_author/#user-contributed-notes
August 8, 2020 at 9:32 am #1393112RandyThanks for the info. I’ve worked with this, but still have trouble.
I did some digging in myPHPAdmin and found my Nicename and I verified IDs and Nicknames. I also tried to make sure I followed the code examples you shared. But nothing has worked yet.
In case it helps, here’s my current code (though I’ve tried all the variations in the examples) β¦
add_filter( 'generate_block_element_display', function( $display, $element_id ) { //First Author if ( 10317 === $element_id && is_author('6')) { $display = true; } //Second Author if ( 10331 === $element_id && is_author('5')) { $display = true; } return $display; }, 10, 2 );
Thanks!
August 8, 2020 at 4:22 pm #1393364TomLead DeveloperLead DeveloperA good way to test your conditions is to do this:
add_action( 'generate_before_header', function() { if ( is_author('6') ) { var_dump('hello'); } } );
Does that output “hello” before the header on the author page you’re targeting?
August 8, 2020 at 5:20 pm #1393387RandyNo, it doesn’t, actually. Also tried Author ID 5. I added it as a new snippet in Code Snippets.
Not really sure what this means, other than the test failed. π
For what it’s worth, I did add some code to the Dashboard, with the code at #8 on this page to “Add the User ID column” partly to see if it would work and to verify user ID numbers (it worked).
August 9, 2020 at 5:44 am #1393821DavidStaffCustomer SupportTry this snippet instead:
add_filter( 'generate_block_element_display', function( $display, $element_id ) { global $post; $post_author_id = $post->post_author; //First Author if ( 10317 === $element_id && $post_author_id = '6' ) { $display = true; } //Second Author if ( 10331 === $element_id && $post_author_id = '5' ) { $display = true; } return $display; }, 10, 2 );
August 9, 2020 at 6:32 pm #1394613RandyThanks for the suggestion. I was hopeful, but it wasn’t successful, either.
After trying it, I thought I would take a shot in the dark and check with the webhost just to see if they thought there might be any conflicts in the setup. They didn’t see anything or have anything to suggest. I was just glad they looked into it. π
August 10, 2020 at 9:32 am #1395769TomLead DeveloperLead DeveloperPerhaps something like this?:
add_filter( 'generate_block_element_display', function( $display, $element_id ) { global $post; $post_author_id = $post->post_author; //First Author if ( 10317 === $element_id && 6 == $post_author_id ) { $display = true; } //Second Author if ( 10331 === $element_id && 5 == $post_author_id ) { $display = true; } return $display; }, 10, 2 );
August 10, 2020 at 11:01 am #1395926RandyHmmm. This is interesting. The one thing I noticed with this latest code is that, while it didn’t change anything on the individual post (still showing both author blocks), it only showed MY author block on the homepage/index, but it did even on the ones I didn’t write. The previous code showed both author blocks on the index page.
The first code(s) didn’t add the author blocks to the index page.
Thanks for all of your help. I certainly didn’t know this was going to be such a chore. π
August 10, 2020 at 1:41 pm #1396116TomLead DeveloperLead DeveloperSo you’re showing the author boxes within archives as well? Not just within single posts?
August 10, 2020 at 2:44 pm #1396185RandyYes. On checking again, my author block appears at the bottom of every page — including Contact, About, Archives, Subscribe. But on the single posts, both author blocks show up.
August 11, 2020 at 9:00 am #1397410TomLead DeveloperLead DeveloperCan you try:
1. Removing any and all Display Rules from the actual Element.
2. Adding this code:
add_filter( 'generate_block_element_display', function( $display, $element_id ) { if ( is_singular() ) { global $post; $post_author_id = $post->post_author; //First Author if ( 10317 === $element_id && 6 == $post_author_id ) { $display = true; } //Second Author if ( 10331 === $element_id && 5 == $post_author_id ) { $display = true; } } return $display; }, 10, 2 );
August 11, 2020 at 11:26 am #1397611RandyOkay, I removed the one display rule I had (posts/all posts). This worked for the single posts for each author (yay!), but β¦
Here’s what else is happening:
- My author block appears at the bottom of each page (About, Contact, etc.).
- My author block appears at the end of each post on the main index page, even for the posts written by my wife (but, it shows her block when clicking on the single post).
- When I click on her author page, it shows her block with each post.
Thanks! π
-
AuthorPosts
- You must be logged in to reply to this topic.