• Resolved dalemoore

    (@dalemoore)


    I’m trying to determine how I can list all of the attachments for a specific property in the property overview, rather than the individual property page. We won’t be using the “single” version of the property listing, instead, everything will be in the property overview. I’ve tried <?php echo do_shortcode('[list_attachments]'); ?> but it doesn’t work. Any ideas? I would also like to insert the actual attributes in there as well, such as price, size, and other attributes I setup under WP Property > Settings > Developer.

    I’ve also tried this code, which works to list the attachments on the single page, but when used in the property overview code, just lists ALL attachments for every property in each one, not the ones that belong to just that property.

    <?php
    
        // Property Attachments - PDFs, Word Docs, etc.
    $args = array(
              'post_type' => 'attachment',
              'post_mime_type' => 'application/pdf,application/msword',
              'numberposts' => -1,
              'post_status' => null,
              'post_parent' => $post->ID,
              'orderby' => 'menu_order',
              'order' => 'desc'
              );
            $attachments = get_posts($args);
    
            if ($attachments) {
              echo '<div class="property_docs"><h3>Property Documents</h3><ul>';
    
              foreach ($attachments as $attachment) {
                echo '<li><a href="'.wp_get_attachment_url($attachment->ID).'" target="_blank">';
                echo $attachment->post_title;
                echo '</a></li>';
              }
    
              echo '</ul></div>';
            }
        ?>

    https://wordpress.org/plugins/wp-property/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter dalemoore

    (@dalemoore)

    Okay, I figured out how to output the actual attributes of the property into the property overview, for my own and others future reference, you use @draw_stats. For example:

    <?php
                        if($property['property_type']=='site') { // Output stats for Sites
                          echo @draw_stats('display=list&class=testing&exclude=port,rail,salelease,phone_number,type_property&sort_by_groups=false', $property );
    
                        }
                        else { // Output stats for Buildings
                          echo @draw_stats('display=list&exclude=phone_number&sort_by_groups=false', $property );
                        }
                      ?>

    In draw_stats, you can “exclude” or “include” which property stat you want to output by using a comma-separated list.

    I still can’t figure out how to output the attachments for each property in the property overview listings, though. Has anyone had success with this? I know it’s not probably a frequent request.

    Thanks.

    Thread Starter dalemoore

    (@dalemoore)

    If I use this code:

    <?php
    
        // Property Attachments - PDFs, Word Docs, etc.
    $args = array(
              'post_type' => 'attachment',
              'post_mime_type' => 'application/pdf,application/msword',
              'numberposts' => -1,
              'post_status' => null,
              /* 'post_parent' => $post->ID, */
              'orderby' => 'menu_order',
              'order' => 'desc'
              );
            $attachments = get_posts($args);
    
            if ($attachments) {
              echo '<div class="property_docs"><h3>Property Documents</h3><ul>';
    
              foreach ($attachments as $attachment) {
                echo '<li><a href="'.wp_get_attachment_url($attachment->ID).'" target="_blank">';
                echo $attachment->post_title;
                echo '</a></li>';
              }
    
              echo '</ul></div>';
            }
        ?>

    It will list all attachments for ALL properties in each property over listing, which is close to what I want… except I just want each listing to only list its own attachments… So it seems to me that post_parent is the thing I may be missing? What the proper value is for this field. Hmmm…

    Thread Starter dalemoore

    (@dalemoore)

    I figured it out.

    Instead of using property-overview.php’s loop, try using property-overview-plain_list.php.

    if($properties): ?>
    <ul class="<?php wpp_css('property_overview_plain_list::row_view', "wpp_row_view"); ?>">
        <?php foreach($properties as $property_id): ?>
    
        <?php $property = prepare_property_for_display(get_property($property_id, ($show_children ? "get_property['children']={$show_property['children']}" : ""))); ?>
    
        <li class="<?php wpp_css('property_overview_plain_list::property_div', "property_div"); ?>">
          <a href="<?php echo $property['permalink']; ?>"><?php echo $property['post_title']; ?></a>
          <?php if($show_children && $property['children']): ?>
            <ul class="child_properties">
                <?php foreach($property['children'] as $child): ?>
                <li><a <?php echo $in_new_window; ?> href="<?php echo $child['permalink']; ?>"><?php echo $child['post_title']; ?></a></li>
                <?php endforeach; ?>
            </ul>
          <?php endif; ?>
        </li>
        <?php endforeach; ?>
    </ul><?php // .wpp_property_list ?>
    
    <?php endif; ?>

    Then, use the regular attachment code, and it should work – with $property_id as the post_parent. This code will show all attached PDFs and Word docs inside each listing on your property-overview. 🙂

    <?php
                    // Property Attachments - PDFs, Word Docs, etc.
                    $args = array(
                      'post_type' => 'attachment',
                      'post_mime_type' => 'application/pdf,application/msword',
                      'numberposts' => -1,
                      'post_status' => null,
                      'post_parent' => $property_id,
                      'orderby' => 'menu_order',
                      'order' => 'desc'
                      );
                    $attachments = get_posts($args);
    
                    if ($attachments) {
                      echo '<div class="property_docs"><h3>Property Documents</h3><ul>';
    
                      foreach ($attachments as $attachment) {
                        echo '<li><a href="'.wp_get_attachment_url($attachment->ID).'" target="_blank">';
                        echo $attachment->post_title;
                        echo '</a></li>';
                      }
    
                      echo '</ul></div>';
                    }
                    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘List all attachments for a property in property overview?’ is closed to new replies.