Check listing belongs to which CPT in preview

This topic contains 5 replies, has 2 voices, and was last updated by  Alex Rollin 6 years, 11 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #414136

    Sheshraj Ghimire
    Expired Member
    Post count: 14

    Hello, I would like to know the code that will help me determine which CPT listing is being created and want to display content accordingly in

    if( $preview ) {}

    mode.

    I am trying to add header image banner to different listing type conditionally if pictures for that listing is not added at the time of creation.

    #414146

    Alex Rollin
    Moderator
    Post count: 27815

    Hello,

    Can you clarify which page?
    Do you mean you want to show ‘something’ on the Listing Preview page?
    And make the display different, based on which CPT?

    That is not possible without a customization, but we will keep it in mind for GD V2.

    You can set a default image for each CPT. For places, for example :

    GD > Custom Post Types > Place > Advanced Mode > Upload default image

    You can also upload a default listing image by CPT Category for each category at:

    WP > Places > Place Categories > Category > Default listing image

    Thanks for writing in

    #414153

    Sheshraj Ghimire
    Expired Member
    Post count: 14

    I want to add it conditionally. Let me explain.
    I have restaurant CPT and Hospital CPT.
    I also have 2 different banner images uploaded to media: one for Restaurant and one for Hospital

    Now, when user add new restaurant listing and doesn’t select any image file, I want to show banner image of restaurant. I think I can display it on page when it’s published, but I can’t find any code that let me know that this listing that is being added is of which post type so I can conditionally show it in preview mode. (i.e. in listing preview page)

    Is there any such codes to know if new listing belong to which CPT without being published?

    #414221

    Alex Rollin
    Moderator
    Post count: 27815

    Hello,

    You can set a default image for each CPT. For places, for example :

    GD > Custom Post Types > Place > Advanced Mode > Upload default image

    You can also upload a default listing image by CPT Category for each category at:

    WP > Places > Place Categories > Category > Default listing image

    So, let’s say you have a CPT for restaurant.

    Go to WP > Restaurant Categories

    For each category, add the Restaurant image as the default listing image.

    That will work to make sure there is a default image for the listing.

    #414412

    Sheshraj Ghimire
    Expired Member
    Post count: 14

    Hello Alex,
    Thank you for your suggestion. However, I already did all of that. I wasn’t looking for all the options that were present. They could only work once the listing is published(or maybe only in my case, I don’t know). I was asking for code that will let me know that new listing belongs to which CPT type. Maybe I wasn’t able to clarity that before. However, I finally found it.

    geodir_action_geodir_set_preview_post();

    I used it in following way and solved what I was trying to achieve:

    
    
    global $post, $preview;  
        if ( $preview ) {
            geodir_action_geodir_set_preview_post(); //sets $post value when previewing post
            $post_type = $post->listing_type; 
        } else { 
            $post_type = $post->post_type; 
        }
    
        if( $post_type == "gd_restaurant" ) {
            $postbanner_img_url = "$defult_url/wp-content/uploads/restaurant-banner.jpg"; //this way the image is displayed on restaurant listing page no matter the post status is
        }
    #414457

    Alex Rollin
    Moderator
    Post count: 27815

    Hello,

    Glad you were able to find a solution that works for you.

    Thanks for letting us know!

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