FYI:
Removed the brackets { and } from the string to verify output without executing it as shortcode. Result as expected was:
latestbyauthor author=John Smith show=10
Shortcode of [latestbyauthor author=John Smith show=10] fails to display John Smith’s posts. If I searched “John Smith”, PHP passes a string with backslash inserted front & back – and I get my own posts.
Anything between ‘author=’ and ‘show=’ should be considered username.
The Latest Post by Author plugin was designed to work with login usernames, not display names. Also, according to the WordPress shortcode documentation, if a shortcode value has a space in it, then quotation marks are required. If you wouldn’t mind posting the code you’re using, I can try to test it out for you.
Programming various machines and languages for 50 years.
My first attempt at PHP.
Code on the page is:
<?php
if (!isset($_POST[‘submit’]))
{
echo ‘<form action=”” method=”post”>’;
echo ‘Author: <input type=”text” name=”who”>
‘;
echo ‘Number:<input type=”text” name=”many” value=”10″>
‘;
echo ‘<input type=”submit” name=”submit” value=”Search”>’;
echo “</form>”;
}
else
{
$q = “]”;
$x = “[latestbyauthor author=”;
$w = $_POST[‘who’];
$y = ” show=”.$_POST[‘many’];
$z = “$x”.”$w”.”$y”.”$q”;
echo “$z”;
}
?>
Works for users with no space/blank in name.
Trying to debug the problem, I removed the [ ] from $q and $x so that $z was just a string instead of shortcode.
Search for John Doe created string:
latestbyauthor author=John Doe show=10
Search for “John Doe” created string:
latestbyauthor author=\”John Doe\” show=10
Don’t know where the \s came from. My bad PHP?
The code posted above lacks some ending apostrophes and/or semi-colons which were in the code – sloppy copy/paste 🙁
Fixed the problem by tweaking my cod based on your comment that quotes are needed.
Instead of framing the name with quotes when entering into the form, I inserted quotes before and after the name when constructing the string for the short code.
Search for John Smith now yields shortcode:
[latestbyauthor author=”John Smith” show=10]
It works!
Search for John yields shortcode:
[latestbyauthor author=”John” show=10]
Quotes not needed but cause no problem. 🙂
BTW: Thanks for the prompt response – and the plugin.
Working code in case someone else wants a Page:
<?php
/*
Search for posts by author.
Returns list of links to posts.
Requires:
exec_php plugin
latestbyauthor plugin
*/
if (!isset($_POST[‘submit’]))
{
echo ‘<form action=”” method=”post”>’;
echo ‘Author: <input type=”text” name=”who”>
‘;
echo ‘Number:<input type=”text” name=”many” value=”10″>
‘;
echo ‘<input type=”submit” name=”submit” value=”Search”>’;
echo “</form>”;
}
else
{
$v = ‘”‘;
$q = “]”;
$x = “[latestbyauthor author=”.”$v”;
$w = $_POST[‘who’];
$y = “$v”.” show=”.$_POST[‘many’];
$z = “$x”.”$w”.”$y”.”$q”;
echo “$z”;]
}
?>
I’m glad to hear that solved the problem for you. Thanks for sharing your updated code!
Code work bur you disable Editors from editing Admin’s posts, which is a problem. Role Manager plugi N/A or not supported by current WP.
Is there a way to only block Editors if the post has PHP? We don’t put PHP in posts (altho we could, so I understand your logic), but I would like to use it ina Page (which editors never touch).
I’m not really sure about the Role Manager plugin and how it handles PHP in posts and pages. Sorry about that.
My mistake – the problem with disabling Editors from editing Admin’s post was not your plugin but the Exec-PHP plugin which is needed to execute your shortcode via PHP within a page. Problem solved by promoting he two Editors involved.
Thanks for posting your findings!