rest api - Create a new page on front page for logged in user

admin2025-06-03  2

I am going to find a way for logged in users to create pages from front page. For example there are three buttons so called button1,2,3. When logged in users clicks on button1, a page with title newyork1 is created and if user clicks on New York button for one more time, a new page newyork1-1 and newyork1-2 are created and the same logical with Tokyo and London. I have tried Wordpress Rest API then wp_insert_post() function but it not working as it cannot get the author and title as i aspected. If you guys have a better idea, please help. Thank you

<ul> 
    <li> <a href="" data-name="newyork"> New York</a></li> 
    <li> <a href="" data-name="tokyo"> Tokyo</a></li>
    <li> <a href="" data-name="london"> London</a></li>
</ul>

I am going to find a way for logged in users to create pages from front page. For example there are three buttons so called button1,2,3. When logged in users clicks on button1, a page with title newyork1 is created and if user clicks on New York button for one more time, a new page newyork1-1 and newyork1-2 are created and the same logical with Tokyo and London. I have tried Wordpress Rest API then wp_insert_post() function but it not working as it cannot get the author and title as i aspected. If you guys have a better idea, please help. Thank you

<ul> 
    <li> <a href="" data-name="newyork"> New York</a></li> 
    <li> <a href="" data-name="tokyo"> Tokyo</a></li>
    <li> <a href="" data-name="london"> London</a></li>
</ul>
Share Improve this question asked Jan 31, 2019 at 9:15 TonyTony 12 bronze badges 1
  • Hi @Tony, your question is too vague and not appropriate for this forum, you are unlikely to get any answers. You are seeking to solutions to your specific problem, and not to a general WP functionality problem. Questions which have a real value for the rest of the community (ie that others may face too) are more likely to get you answers. – Aurovrata Commented Feb 1, 2019 at 8:55
Add a comment  | 

2 Answers 2

Reset to default 0

How about redirecting specific users with a set of redirect rules? You can try using Peter’s Login Redirect plugin. Follow these steps:

  1. Install and activate the plugin.
  2. Hover on Settings in the left sidebar.
  3. Click on Login/logout redirects.
  4. Enter your custom Login URL for specific users.

Already has a solution here You have modify a bit to use it. 1. 'post_type' => 'post', change to 'post_type' => 'page',

Also your user must have capabilities to create page. Here is another solution on how to handle that.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748957769a315151.html

最新回复(0)