Get the ID of the previewed listing

This topic contains 10 replies, has 5 voices, and was last updated by  Antonella Gallino 6 years, 1 month ago.

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

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #455389

    Antonella Gallino
    Buyer
    Post count: 73

    Hi there,

    I made some customizations of the listing page. However they don’t show up in the listing preview page (the one an user see when they register).

    The problem is that my code take the ID of the page and not of the previewed listing.

    So my question is: how can I get the ID of the previewed listing when I’m in the preview listing page? I believe is the value called pid.

    Thanks a lot,

    Simone

    #455392

    Antonella Gallino
    Buyer
    Post count: 73

    Hi again,

    I solved the issue using the function geodir_action_geodir_set_preview_post

    https://wpgeodirectory.com/codex/codex/geodirectory_functions/geodir_action_geodir_set_preview_post/

    Thanks,

    Simone

    #455396

    Kor
    Moderator
    Post count: 16516

    Hi Simone,

    Thanks for the update.

    #455464

    Antonella Gallino
    Buyer
    Post count: 73

    Hi Kor,

    sorry to open this again. I’m using this code to get the previewed listing ID, but it works only if the listing is already been saved.

    If I preview a new listing it doesn’t work

    
    
    global $post, $preview;
        
        if ($preview) {
            /**
             * Called on the details page if the page is being previewed.
             *
             * This sets the value of <code>$post</code> to the preview values before the main content is called.
             *
             * @since 1.1.0
             */
            do_action('geodir_action_geodir_set_preview_post'); // set the $post to the preview values
            if (defined( 'GD_TESTING_MODE' )) {
                global $post;
            }
            
            $postid = $post->pid;
    
        } else {
            $postid = $post->ID;
        }

    What am I missing?

    Simone

    #455465

    Alex Rollin
    Moderator
    Post count: 27815

    I have flagged your question for the developers to see if they can point you in the right direction.

    #455546

    Patrik
    Moderator
    Post count: 1971

    Hi,

    It would be great if you show us the full code so that we can get more idea about what you are trying to do and what is the issue. Actually, the post ID will generate on saving the post only and not on a preview.

    If possible provide Admin and FTP details in private reply and let us know the file and the function you are implementing the code.

    Regards,
    Patrik

    #455562

    Antonella Gallino
    Buyer
    Post count: 73
    This reply has been marked as private.
    #455570

    Patrik
    Moderator
    Post count: 1971
    This reply has been marked as private.
    #455571

    Antonella Gallino
    Buyer
    Post count: 73
    This reply has been marked as private.
    #455572

    Kiran
    Moderator
    Post count: 7069

    Hello Simone,

    I looked your code and have used

    
    
    $cover_photo = geodir_get_post_meta( $postid, 'geodir_foto_copertina', true);
    $logo = geodir_get_post_meta( $postid, 'geodir_logo_scheda', true);

    to retrieve field value. This will not work on preview of new listings, because new listing data only saved after listing is saved.

    You should use like

    
    
    $cover_photo = isset( $post->geodir_foto_copertina ) ? $post->geodir_foto_copertina : '';
    $logo = isset( $post->geodir_logo_scheda) ? $post->geodir_logo_scheda: '';

    Kiran

    #455573

    Antonella Gallino
    Buyer
    Post count: 73

    Hi Kiran,

    thank you very much!

    I’ll test that then.

    Have a nice day!

    Simone

Viewing 11 posts - 1 through 11 (of 11 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