add_filter and calling WP functions
-
I’m adding a filter in functions.php and I’m a bit stumped why I can’t get things to work. Have been pulling my hair out for a few days now 🙂 Not sure if it’s a WordPress or PHP issue, but I can’t figure it out.
In the original function, one can get the user ID with:
{marker_id}
I can output this in my filter and get a user ID 111. I can also add it to a variable and then output that variable:
$user_id = ‘{marker_id}’;
So far, so good. The problems start when I try to use this user ID inside my filter:
function wpgmp_location_criteria($infowindow_setting, $map) { $user_id = '{marker_id}'; $user_url_A = get_author_posts_url('{marker_id}'); $user_url_B = get_author_posts_url($user_id); $user_url_C = get_author_posts_url('111'); $infowindow_setting .= '#1: ' . $user_id . '<br />'; $infowindow_setting .= '#2: ' . $user_url_A . '<br />'; $infowindow_setting .= '#3: ' . $user_url_B . '<br />'; $infowindow_setting .= '#4: ' . $user_url_C . '<br />'; return $infowindow_setting; } add_filter('wpgmp_infowindow_message', 'wpgmp_location_criteria', 1, 2 );As can be seen in this example, I’m trying to get the user posts URL. On #1 I get the user ID just fine. On #4 I hardcode the user ID and that gets the correct URL:
https://mydomain.com/authors/author-name/
But for #2 and #3 I only get:
And this is what I can’t figure out. The {marker_id} and $user_id that I use in #2 and #3 output the correct user ID if I output them directly, but not when using them in the get_author_posts_url() function.
Is this due to how add_filter() works, how PHP deals with numbers, or.. I can’t figure it out!
The topic ‘add_filter and calling WP functions’ is closed to new replies.