简体   繁体   中英

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(); but it's not working.

update, from 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

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

Am I putting it in the wrong place, perhaps?

You can try trigger :

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

Here is a jsFiddle example how to use 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. they never work together. place the jQuery code in the custom post type page template instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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