Wait a minute... This content is very very old. We no longer sell or support this theme version. New Topics
Version 9
Jonathan Bar Ner
0 points
Beginner
Goal:I want that the my-account page will redirect automatically to the user’s (hopefully-single) listing.
Background:In my Business Directory-based site, I want each user to have a single listing, that I will create when creating the user itself. Therefore, when a user logs-on, I don’t want him to see the full “my-account” page, but get directly to edit his own listing.
My Solution
1. Create a new page called “my-account-redirect”, and set My Account to it in General Settings => Page & Button Links.
2. Install the plugin Insert PHP Code Snippet by XYZScript.
3. Create a PHP snippet with the following code: $q = ‘post_type=’ . THEME_TAXONOMY . ‘_type&author=’ . get_current_user_id();
$the_query = new WP_Query( $q );
if ( $the_query->have_posts() ) {
$the_query->the_post(); # Get the first post – I assume there’s only one
$newUrl = ‘/add-listing/?eid=’ . get_the_ID();
wp_redirect($newUrl, /*status*/ 301);
} else {
# TODO: Create new listing
}
4. Add the snippet to “my-account-redirect” page.
5. Add text to the page: “Oops… If you can see this page, this means that your listing is missing. Please contact the site administrator so he’ll create your listing.”
Does this look right? Any suggestions about the code or process?
Goal:I want that the my-account page will redirect automatically to the user’s (hopefully-single) listing.
Background:In my Business Directory-based site, I want each user to have a single listing, that I will create when creating the user itself. Therefore, when a user logs-on, I don’t want him to see the full “my-account” page, but get directly to edit his own listing.
My Solution
1. Create a new page called “my-account-redirect”, and set My Account to it in General Settings => Page & Button Links.
2. Install the plugin
Insert PHP Code Snippetby XYZScript.3. Create a PHP snippet with the following code:
$q = ‘post_type=’ . THEME_TAXONOMY . ‘_type&author=’ . get_current_user_id();$the_query = new WP_Query( $q );
if ( $the_query->have_posts() ) {
$the_query->the_post(); # Get the first post – I assume there’s only one
$newUrl = ‘/add-listing/?eid=’ . get_the_ID();
wp_redirect($newUrl, /*status*/ 301);
} else {
# TODO: Create new listing
}
4. Add the snippet to “my-account-redirect” page.
5. Add text to the page: “Oops… If you can see this page, this means that your listing is missing. Please contact the site administrator so he’ll create your listing.”
Does this look right? Any suggestions about the code or process?
Members Only Content
This reply is for PremiumPress customers only.
Login Now