• Author
  • stonetuc

    Hello again, I am using this code snippet, but it does not show me the image (it does not bring the address of it), what is the error?

    <div class=”” style=”background-image: url(‘<?php echo esc_url( $array->get_image__url( ‘ht_portrait_small’ ) ); ?>’)”>

    ps: it is the part that doesn’t work, other fields like the title if I can load them without problems; It is with the image that I cannot


    Another query, how can I extract the featured image from a category?


    1. Please make sure that the $array variable in your code example contains the listing object.

    2. If you have a listing category object, please check how the featured image is fetched in the HivePress source code https://github.com/hivepress/hivepress/blob/master/templates/listing-category/view/block/listing-category-image.php


    Since the listing is just a custom post type you can also get listing image in this way (by listing ID) https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/


    I still have the problem to extract the image from a category, this is my code:
    function salcodes_cat( $atts ) {

    // Taxonomy for product categories
    $taxonomy = ‘hp_listing_category’;

    // Get parent product categories’
    $parent_product_cats = get_terms( $taxonomy, array( ‘parent’ => 0, ‘orderby’ => ‘slug’, ‘hide_empty’ => false ) );

    foreach ( $parent_product_cats as $product_cat_obj ) {
    $term_id = $product_cat_obj->term_id; // term ID
    $term_name = $product_cat_obj->name; // term Name
    $term_slug = $product_cat_obj->slug; // term slug
    echo ‘<br>’;
    echo $term_name;
    echo $term_id;
    echo $term_slug;

    $thumbID = get_post_thumbnail_id($product_cat_obj->term_id);
    $imgFeatured = wp_get_attachment_image_src( $thumbID, ‘thumbnail’ );




    I tried to guide myself from the source code but I still can’t find the solution.
    What I can do?. I need to list the HivePress categories with their image, (to later add different functionalities to those of the theme, for example redirect a category to a certain template)


    any solution?


    Sorry, but I can’t verify and test your custom code, it’s not part of support (it includes help with existing features and fixing bugs), although I often provide simple code snippets. Please try using existing blocks or shortcodes for displaying categories, like [hivepress_listing_categories]. If you have to code a custom solution please check the WordPress developer docs and/or HivePress source code.

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

You must be logged in to reply to this topic.


Sign In

Don't have an account? Register

Forgot password?


Already have an account? Sign In

Forgot password?

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.