Link to users listing from listing id

This topic contains 12 replies, has 4 voices, and was last updated by  Alex Howes 6 years, 9 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #432276

    Alex Howes
    Expired Member
    Post count: 175

    Hello,

    I’d like to add a link which goes to a user’s listing detail page, as part of a snippet. Is there a way to get the url by specifying the listing id?

    Thanks,
    Alex

    #432293

    Paolo
    Site Admin
    Post count: 31211

    I don’t understand the question, I’m sorry, please try to explain it with more details and possibly an example.

    Thanks

    p.s. from the sound of it, this would be a customization

    #432312

    Alex Howes
    Expired Member
    Post count: 175

    Sorry, I’ll try to explain better.

    One of my CPTs is CVs. I’m adding some extra information to a custom tab on the profile page as part of a snippet, to allow some users to view some other users’ CVs. I’ve written:

    echo '<a href="url">View Worker CV</a>';

    where the url I’d like to go to is a user’s listing detail page. I have the listing id of the listing. Is this possible? I’m not sure how to get the url because the page is dynamic.

    Thanks,
    Alex

    #432314

    Alex Rollin
    Moderator
    Post count: 27815
    #432346

    Alex Howes
    Expired Member
    Post count: 175

    Hi Alex, I don’t want to get the listing data, I want to get the url of the listing page.

    Alex

    #432488

    Paolo
    Site Admin
    Post count: 31211

    HI Alex,

    I passed your question to the devs. They’ll let you know asap.

    Sorry to keep you waiting, but being a customization this is has lower priority.

    Thanks

    #432495

    Alex Howes
    Expired Member
    Post count: 175

    Thanks Paolo, no problem. Hope you’re enjoying memorial day 🙂

    #432527

    Kiran
    Moderator
    Post count: 7069

    Hi Alex Howes,

    Use following code snippet to get listing url from id.

    
    
    function gd_cv_link( $atts = array(), $content = '' ) {
        $atts = shortcode_atts( array(
            'id' => 0,
        ), $atts, 'gd_cv_link' );
    
    	if ( ! empty( $atts['id'] ) ) {
    		$url = get_permalink( (int)$atts['id'] );
    	} else {
    		$url = '';
    	}
    
    	return $url;
    }
    add_shortcode( 'gd_cv_link', 'gd_cv_link' );

    Usage:

    <a href="[gd_cv_link id="273"]">View Worker CV</a>

    replace 273 with id you want.

    Kiran

    #432550

    Alex Howes
    Expired Member
    Post count: 175

    Thanks for your response Kiran.

    I’ve added it, but instead of the link going to the user’s CV, it reloads the same page but with [gd_cv_link%20id=cv_id]/ appended on the end of the url. Do you know what the problem might be?

    Thanks,
    Alex

    #432551

    Kiran
    Moderator
    Post count: 7069

    Send your site admin link & admin credentials, i will take a look.

    Kiran

    #432617

    Alex Howes
    Expired Member
    Post count: 175

    I’m writing it programmatically as part of a snippet. The snippet creates a new tab on the user’s profile and adds links to other users’ CVs. The $cv_id is a string containing the id of the listing, in this case ‘438’ (I’ve checked this). The tab and link are being created fine. When you click on the link, it reloads the page (the user’s account page) but with the url appended by /[gd_cv_link%20id=cv_id]/. I’ve also checked it using ‘438’ rather than $cv_id, but this doesn’t make a difference. The section of my code is:

    
    
    $cv_url = gd_cv_link($cv_id);
    echo '<a href="[gd_cv_link id=$cv_id]">View Worker CV</a>';
    #432677

    Kiran
    Moderator
    Post count: 7069

    Hello,

    Try this:

    
    
    $cv_url = get_permalink( $cv_id );
    echo '<a href="' . $cv_url . '">View Worker CV</a>';

    Kiran

    #432737

    Alex Howes
    Expired Member
    Post count: 175

    Great, thanks! 🙂

Viewing 13 posts - 1 through 13 (of 13 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount