Hi @cigno76,
Thank you for your feedback, we’re happy to hear you enjoy using WPCode.
Regarding your request – can you access the post in the browser when you are not logged-in? I’m not sure what you are trying to do with the request but would it be an option to load the post data directly through the WP functions instead of loading it using file_get_contents?
If you can provide more info about what the snippet is supposed to do we might be able to find an alternative solution.
Dear Mircea Sandu,
no, I cannot access the post in the browser when you I ‘m not logged-in.
This is the url (I replaced the domain):
https://mydomain.xx/wp-admin/post.php?post=24123&action=edit&lang
In practice, from the post that displayed in the admin area of wordpress, I want to capture a string from its html code.
Any alternative would be fine for me.
Thank you,
Nicola
Hi @cigno76,
I see, you can’t access that URL directly using file_get_contents as in that instance you are not logged-in. It should be much easier & safer to grab the value from the database/using a WP function if it’s something specific to that post.
If you can share what part of the post you are trying to grab I can try to point you to the function you can use to get that directly without having to parse the HTML.
Hi Mircea Sandu,
unfortunately it is not information available in the database, the only way is to capture it from the html code.
thanks for your time,
Nicola
Dear Mircea Sandu,
Do you have any idea how to get a post (kind file_get_contents function) that requires login?
Best regards,
Nicola
Hi @cigno76,
I don’t have a great solution for that, if the value you are trying to load is specific to the post you are editing surely there must be an alternative way to get that. Either through a call to the database or in a similar manner to how it is loaded in the edit screen. Without more context I would just be guessing.
Sending an authenticated request with file_get_contents is possible but you will need to look into how WordPress authentication works and how you can send cookies with file_get_contents.
Dear, I understand, anyway thanks for your time