How can get destinations featured image in custom loop?

Homepage Forums WP Travel How can get destinations featured image in custom loop?

Tagged: 

This topic contains 12 replies, has 3 voices, and was last updated by  Support Team 2 weeks, 1 day ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #21286

    karankcoresys
    Participant

    Please help:
    Here is my code:

     <?php
    $custom_terms = get_terms('travel_locations');
    foreach($custom_terms as $custom_term) {
    $term_link = get_term_link( $custom_term );
    wp_reset_query();
    $args = array('post_type' => 'itineraries',
    'tax_query' => array(
    array(
    'taxonomy' => 'travel_locations',
    'field' => 'slug',
    'terms' => $custom_term->slug,
    ),
    ),
    ); ?>
    <?php 
    $loop = new WP_Query($args);
    if($loop->have_posts()) { ?>
    <a href="<?php echo $term_link;?>"> <img src="http://rankonone.com/dev/westchina/wp-content/uploads/2019/10/Altai.jpg">
    <h2><?php echo $custom_term->name; ?></h2>
    </a>
    <?php
    while($loop->have_posts()) : $loop->the_post();
    ?>
    <a href="<?php echo get_permalink(); ?>">
    <h3><?php echo get_the_title()?></h3></a>
    <?php
    endwhile; ?>
    <?php }?>
    #21295

    wensolutions
    Keymaster

    Hello @karankcoresys,

    The help you are asking for is beyond the support we offer for our Product. This has to be handled by the professional developer.

    Hope you understand.

    If you have any confusion related to the plugin then please let us know.

    Thank you.

    #21296

    karankcoresys
    Participant

    Please, sir help, it’s not a big problem from your side, My client purchased the pro version of wptravel. We have the license key. It’s just the last problem we need to fix and our website will gonna complete.

    #21303

    wensolutions
    Keymaster

    Hello @karankcoresys,

    As for now, to resolve the issue please add below-given code inside the loop.

     $term_featured_image_id = get_term_meta( $custom_term->ID, 'wp_travel_trip_type_image_id', true );
            $image_url = wp_get_attachment_url( $term_featured_image_id );

    Also, we cannot help you further regarding the code related issue as it may generate complex issues on client-side so we recommend you taking help from our professional developer.

    Thank you.

    #21341

    karankcoresys
    Participant

    Thank you for the reply, but it’s not worked, your plugin must have the taxonomy image display option.

    i tried code but not worked.

    please let me know how to use this code!

    `<?php
    $post_type = ‘itineraries’;
    $custom_tax = ‘travel_locations’;
    $custom_args = array(
    ‘parent’ => 0
    );
    $custom_terms = get_terms($custom_tax, $custom_args);
    foreach($custom_terms as $custom_term) {
    $term_link = get_term_link( $custom_term );
    wp_reset_query();
    $args = array(‘post_type’ => ‘itineraries’,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘travel_locations’,
    ‘field’ => ‘slug’,
    ‘terms’ => $custom_term->slug,

    ),
    ),
    ); ?>
    <?php
    $loop = new WP_Query($args);
    if($loop->have_posts()) { ?>
    <?php
    while($loop->have_posts()) : $loop->the_post(); ?>
    //some content here
    <?php
    endwhile;?>
    <?php } }?>’

    #21365

    Support Team
    Keymaster

    Hello @karankcoresys,

    we are not sure you added the code in your side.

    So please once replace your block of code with the code given below.

    <?php
    $post_type    = 'itineraries';
    $custom_tax   = 'travel_locations';
    $custom_args  = array(
        'parent' => 0
    );
    $custom_terms = new WP_Term_Query(array( // use WP_Term_Query() for terms query instead of get_terms().
    	'taxonomy' => $custom_tax ,
        'hide_empty' => false,
    ));
    foreach ($custom_terms->terms as $custom_term) {
    	$term_link = get_term_link($custom_term);
        $term_featured_image_id = get_term_meta( $custom_term->term_id, 'wp_travel_trip_type_image_id', true ); // Gets id for thr current taxonomy term meta.
    	$image_url = wp_get_attachment_url( $term_featured_image_id ); //THIS IS THE IMAGE URL YOU ARE LOOKING FOR.
        wp_reset_query();
        $args = array(
            'post_type' => $post_type,
            'tax_query' => array(
                array(
                    'taxonomy' => 'travel_locations',
                    'field' => 'slug',
                    'terms' => $custom_term->slug
                )
            )
        );
    ?>
    <?php
        $loop = new WP_Query($args);
        if ($loop->have_posts()) {
    ?>
    <?php
            while ($loop->have_posts()):
                $loop->the_post();
    ?>
    //some content here
    <?php
            endwhile;
    ?>
    <?php
        }
    }
    ?>

    Hope this helps.

    Also, as mentioned in an earlier reply, helping with your code issues is beyond our support scope so we are unable to help you any further.

    Thank you.

    #21366

    karankcoresys
    Participant

    Thank you for your reply!

    I used this code, but it’s now showing an empty page. If my code issue is beyond the support. Just let me know how can I show all destinations on the page with the image in the grid style. please provide any shortcode, code or anything. I just want to show all locations/destinations on the page. Like this: http://rankonone.com/dev/westchina/destinations/, that will be ok if tours not come, just want to show destinations and image.

    Thank you!

    #21373

    Support Team
    Keymaster

    Hello @karankcoresys,

    The code works fine on our side so you can just check the code properly and see what went wrong.

    Further, You can use the shortcode for listing the trip as per the destination and for this refer to below given:

    https://wptravel.io/documentations/user-documentation/#doc-shortcode-50

    Thank you.

    #21375

    karankcoresys
    Participant

    Hello,

    Your code working like this: http://rankonone.com/dev/westchina/destinations-test/

    Still no destination image.

    I am talking about this: https://nimb.ws/VvBijL

    #21387

    Support Team
    Keymaster

    Hello @karankcoresys,

    Can you please provide your admin login detail and FTP so that we can inspect the code in your side and find out the issues?

    Email to send login detail:

    support@wptravel.io

    Thank you.

    #21421

    karankcoresys
    Participant

    Thank you fix the problem! The support is so good!

    #21422

    karankcoresys
    Participant
    #21423

    Support Team
    Keymaster

    Hello @karankcoresys,

    Thank you for the login detail.

    When we tested your site we found that you have not used the code that we have provided. So we have added the code and fix the issue for you. Please verify the issue.

    Also, we are unable to help you any further regarding the code issue so pease take help from the professional developer.

    Thank you.

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

You must be logged in to reply to this topic.