[wp-trac] [WordPress Trac] #40042: Empty Author ID on first time action pre_get_post is called.
WordPress Trac
noreply at wordpress.org
Wed Mar 8 08:42:30 UTC 2017
#40042: Empty Author ID on first time action pre_get_post is called.
--------------------------+----------------------
Reporter: BackuPs | Owner:
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: General | Version: 4.7.2
Severity: normal | Resolution: invalid
Keywords: | Focuses:
--------------------------+----------------------
Comment (by BackuPs):
Hi
Did you try your solution as it does not work for me whereas mine works.
But still why is not the id set to the query record? That is easy to do
from within the wp system.
{{{#!php
<?php
function theme_set_pre_get_posts_vars( $query ) {
if (is_admin()) {
return;
}
if (is_author()) {
$author_name=get_query_var('author_name');
$user = get_user_by( 'user_nicename', $author_name);
Echo '------------> : ';var_dump($user);
}
}
add_action( 'pre_get_posts', 'theme_set_pre_get_posts_vars');
}}}
[[Image(http://i.imgur.com/oDvECDf.png)]]
That is why i was using this
{{{#!php
function theme_set_pre_get_posts_vars( $query ) {
if (is_admin()) {
return;
}
if (is_author()) {
$author_id=get_query_var('author_name');
if (!is_numeric($author_id) && !empty($author_id)) {
$user = get_user_by( 'login', $author_id);
if (isset($user->ID)) $author_id=$user->ID; else
$author_id='';
echo 'the user id'; var_dump($user);
}
}
}
add_action( 'pre_get_posts', 'theme_set_pre_get_posts_vars');
<?php
}}}
[[Image(http://i.imgur.com/XaLh6Hf.png)]]
[[Image(http://i.imgur.com/kxrBdcM.png)]]
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40042#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list