简体   繁体   English

如果用户有帖子,则登录后自动转到帖子编辑。 如果没有帖子,则自动去填写新帖子

[英]If user has post, automatically go to post edit on login. If no post, automatically go to fill out new post

Each user, except Admin, will only have one post each, a custom post type - which is a questionnaire fill-out. 除管理员外,每个用户每个人只有一个帖子,一个自定义帖子类型-这是一个问卷填写表。 I already have the login redirecting to the custom post type page, but I'd like to go one step further and make it really easy for the user. 我已经将登录名重定向到自定义帖子类型页面,但是我想更进一步,使用户非常容易。

If they are logging in for the first time, it would continue to redirect them to the custom post type page, but also auto click on the add custom post type button. 如果他们是首次登录,它将继续将其重定向到自定义帖子类型页面,而且还会自动单击添加自定义帖子类型按钮。

If they have already begun the questionnaire, it would auto click the edit button. 如果他们已经开始问卷,它将自动单击编辑按钮。

I have an auto click working elsewhere, but it's being triggered by a live click on another button. 我在其他地方也有自动点击功能,但这是由另一个按钮的实时点击触发的。

jQuery('.steps-button').live('click', function() {
  jQuery("#publish").click();
});

I've tried using jQuery(".row-actions").find(".edit").click(); 我试过使用jQuery(".row-actions").find(".edit").click(); but it's not working. 但它不起作用。

update, from functions.php 从functions.php更新

 add_filter('login_redirect', 'plugin_admin_redirect'); 
 function plugin_admin_redirect($redirect_to, $url_redirect_to = '', $user = null) { 
 return 'http://mywebsite.com/wp-admin/edit.php?post_type=nanny_profile'; 
 }

earlier in functions.php I have under jQuery(document).ready 在functions.php的早期版本中,我在jQuery(document).ready下拥有

        jQuery(".row-actions").find(".edit").trigger('click');

Am I putting it in the wrong place, perhaps? 也许我把它放错了地方吗?

You can try trigger : 您可以尝试trigger

jQuery(".row-actions").find(".edit").trigger('click');

Here is a jsFiddle example how to use trigger . 是一个jsFiddle示例,如何使用trigger

I think you should not place the code: 我认为您不应放置代码:

 jQuery(document).ready
 jQuery(".row-actions").find(".edit").trigger('click');

in function.php, function.php runs in your server, your questionnaire runs in your user broswer. 在function.php中,function.php在您的服务器中运行,调查表在用户浏览器中运行。 they never work together. 他们从不在一起工作。 place the jQuery code in the custom post type page template instead. jQuery代码放在自定义帖子类型页面模板中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM