Wordpress Author Page 404 - wordpress

I am having a problem with listing all post by given author in author.php
Everything works OK for all user, except admin.
http://somedomain.com/author/MyUser - OK (non admin user!)
http://somedomain.com/author/?author=1 - OK (admin ID = 1)
http://somedomain.com/author/admin - 404
http://somedomain.com/author/User.Admin - 404
http://somedomain.com/author/AdminNickName - 404
The wp_query as follow:
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
$args = array( 'post_type' => 'post', 'author' =>$curauth->ID, 'posts_per_page' => 10 );
$wp_query = new WP_Query($args);
Any solutions? Many thanks!

I had the exact same problem. Here's the solution below. (I'm not sure why this works, but it does.)
Edit your Wordpress database table wp_users. Find your admin account and edit the "user_nicename" field. Put in your login name (or some URL friendly string) and save it.
That's it. On mine, the original value in that column was "Trevor Gehman" and the url for the author page was /author/TrevorGehman/ which returned a 404. I changed the value to "trevorgehman" and then the url became /author/trevorgehman/ and it worked!
http://wphacks.com/change-author-archive-permalink/

Related

Wordpress BO post.php - button Publish/Update not working (error : GET 400 bad request, rest_invalid_param, orderby=menu_order)

I'm facing a weird issue on Wordpress…
I have to do some minor content updates on a Wordpress online since 2020, running perfectly.
But for only one of the CPT, when I want to add/modify a post, the publish/update (and save as draft) buttons not working. I can click on them but nothing happens…
In my console, I spot the following errors :
400 Bad Request GET https://mywebsite/wp-json/wp/v2/challenges?per_page=100&exclude=1921&parent_exclude=1921&orderby=menu_order&order=asc&_fields=id%2Ctitle%2Cparent&context=edit&_locale=user
Uncaught (in promise)
Object { code: "rest_invalid_param", message: "Paramètre(s) non valide(s) : orderby", data: {…} } in data.min.js:2:32702
I can update content without any problem with the quick edit…
Has anyone ever encountered this error?
I found a fix here :
Tim Ross webdevelopment
I had to add to functions.php the following code :
// This enables the orderby=menu_order for Posts
add_filter( 'rest_post_collection_params', 'filter_add_rest_orderby_params', 10, 1 );
// And this for a custom post type called 'portfolio'
add_filter( 'rest_challenges_collection_params', 'filter_add_rest_orderby_params', 10, 1 );
//Add menu_order to the list of permitted orderby values function filter_add_rest_orderby_params( $params ) {
$params['orderby']['enum'][] = 'menu_order';
return $params;
}
The filter hook is called rest_{post_type}_collection_params.
In my case, the post_type is "challenges".

Make an HTTP POST request to upload a file in Wordpress - HTTP POST request get converted to GET

I want to have a HTTP POST link in my Wordpress website that lets another server to post an xml file every hour into the Wordpress server and I save it.
I created an index.php file in folders that map with the route I want, let say I need example.com/jobs/uploadFile, so I created a php file inside the folders /jobs/uploadFile of the root Wordpress directory.
<?php
if( $_SERVER['REQUEST_METHOD'] !== 'POST' ) {
header($_SERVER["SERVER_PROTOCOL"]." Method Not Allowed", true, 405);
exit;
}
$postData = trim(file_get_contents('php://input'));
$xml = simplexml_load_string($postData);
if($xml === false) {
header($_SERVER["SERVER_PROTOCOL"]." Bad Request", true, 400);
exit;
}
$xml->asXml('jobs.xml');
http_response_code(200);
1- I send a HTTP POST request via postman, but somehow the server or Wordpress changes it a HTTP GET request, so always the first if condition is executed. I'm using Laravel forge server with Nginx.
2- Appreciate any security advice about this approach, CORS...?
Thanks for your help
Since it may help others, I answer my question. I was doing it the wrong way. The better way to do it is by using actions in a custom Wordpress plugin. Just create a custom plugin and use add_action inside it:
add_action( 'rest_api_init', function() {
register_rest_route(
'myapi/v1', 'myUploadURL',
[
'methods' => 'POST',
'callback' => 'my_upload_function',
'permission_callback' => '__return_true',
]
);
});
And then you can get the $_FILES of the POST request in the my_upload_function() and save it on your server.

Algolia search index fail

I have installed Algolia search plugin 1.7.0 in my WordPress site. I have also set it up and when I go into indexing the following shows up:
wp_remote_post() failed, indexing won't work. Checkout the logs for more details.
URL called: http://45.77.12.19/wp-admin/admin-post.php
Array
(
[headers] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[server] => nginx/1.12.0
[date] => Tue, 25 Apr 2017 02:23:09 GMT
[content-type] => text/html
[content-length] => 195
[www-authenticate] => Basic realm="Restricted"
)
)
401 Authorization Required
I have tried to add define( 'ALGOLIA_LOOPBACK_HTTP', true ) in the wp-config.php file and followed other steps explained:
https://community.algolia.com/wordpress/frequently-asked-questions.html
I am at a dead end and unsure of what to do now as the algolia indexing won't happen. How can I resolve this?
The Algolia plugin for WordPress needs to be able to access the admin interface over HTTP or HTTPS.
This is the way it creates a loop to deal with the pending tasks.
According to your logs: 'Basic realm="Restricted"', your admin seems protected behind Basic Auth (htpasswd).
To make the queue work in your case, you should provide the plugin with the credentials.
Here is what you need to add to the functions.php file of your active theme.
<?php
// In your current active theme functions.php.
define( 'MY_USERNAME', 'test' );
define( 'MY_PASSWORD', 'test' );
function custom_loopback_request_args( array $request_args ) {
$request_args['headers']['Authorization'] = 'Basic ' . base64_encode( MY_USERNAME . ':' . MY_PASSWORD );
return $request_args;
}
add_filter( 'algolia_loopback_request_args', 'custom_loopback_request_args' );
Note that this will probably change in the upcoming weeks as we are working towards removing that logic.

Reason I would get 403 rest_forbidden accessing WP API taxonomies/name-of-taxonomy?

I'm trying to get a list of taxonomies using the WordPress REST API. Hitting /wp-json/wp/v2/taxonomies/post_tag works fine, but I also have a custom taxonomy called location and accessing /wp-json/wp/v2/taxonomies/location returns a 403 rest_forbidden error.
I can't figure out under what circumstances taxonomy REST access would be forbidden in this way. Any ideas?
You need to set show_in_rest to true when registering your taxonomy.
https://codex.wordpress.org/Function_Reference/register_taxonomy
If your custom taxonomy was created by a plugin and you need to alter it's behaviour try this post :
http://scottbolinger.com/custom-taxonomies-in-the-wp-api/
In short, you can add the code below to your functions file to enable show_in_rest for all custom taxonomies.
function prefix_add_taxonimies_to_api() {
$args = array(
'public' => true,
'_builtin' => false
);
$taxonomies = get_taxonomies($args, 'objects');
foreach($taxonomies as $taxonomy) {
$taxonomy->show_in_rest = true;
}
}
add_action('init', 'prefix_add_taxonimies_to_api', 30);
I hope this helps you.

How to access magento Session in wordpress?

I have read many questions similar to this,
but found no answer
i have to display customer name and cart items in wordpress blog
I have installed Mage Enabler .but always it is showing Invalid Url.
what can be valid url for local pc?
so i also have done like,
require_once ("../app/Mage.php");
umask(0);
Mage::app();
Mage::getSingleton("core/session", array('name' => 'frontend'));
$session = Mage::getSingleton("customer/session");
if($session->isLoggedIn())
{echo "YES";}
else {echo "NO";}
I always get "NO" .. :(
Can anyone please help me how to access magento session in wordpress
Instead of:
$session = Mage::getSingleton("customer/session");
Try:
$session=Mage::getSingleton('customer/session', array('name'=>'frontend') );
Good luck

Resources