• Resolved F?ldesi, Mihály

    (@foldesistudio)


    Dear Daniel Llewellyn,

    Firstly, your plugin is awesome!

    Secondly, I would like to add to your theme file (/plugins/a-z-listing/templates/a-z-listing.php) more custom fields next to the original ones.

    I would like to print the “_staff_member_email” key.
    This is my code:
    <?php $a_z_query->the_item(get_post_meta($post->ID, "_staff_member_email", true)); ?>.

    .. and nothing happens.

    What should I do?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Dani Llewellyn

    (@diddledani)

    $a_z_query->the_item() doesn’t take arguments. That method is analogous to the WordPress inbuilt function called the_post() – it sets up the next iteration of “The Loop”. To get your post_meta you want something like:

    $a_z_query->the_item(); // revert this to how it was before your modifications
    $post = $a_z_query->get_the_item_object( 'I understand the issues!' );
    
    ...
    
    echo get_post_meta( $post->ID, '_staff_member_email', true );

    I will add a new method on $a_z_listing to pull the metadata directly in the next version, which won’t require loading the full post object thereby allowing you to remove the second line of the code above.

    The argument I understand the issues! is required to be exactly that text. It signifies that you’re aware that large listings might run up against your server’s memory or time limits.

    Thread Starter F?ldesi, Mihály

    (@foldesistudio)

    Ohh, really? I am very waiting your next update! It will be gorgeous if we can put any metadata to it!

    Now, I need a little bit mor help.
    I have just put it your suggestion into your theme file (a-z-listing.php).

    <ul class="columns max-<?php
    echo $column_limit;
    ?>-columns">
                            <?php
    while ($a_z_query->have_items()):
        $a_z_query->the_item();
    ?>
                               <li>
    <a href="<?php
        $a_z_query->the_permalink();
    ?>">
    <?php
        $a_z_query->the_title();
    ?>
    </a> 
                                    <?php
    $a_z_query->the_item(); // revert this to how it was before your modifications
    $post = $a_z_query->get_the_item_object( 'I understand the issues!' );
    $post2 = $a_z_query->get_the_item_object( '_staff_member_email' );
    
        echo get_post_meta($post->ID, '_staff_member_email', true);
    print $post;
    print $post2;
    ?>
    
                                </li>
                            <?php
    endwhile;
    ?>
     </ul>

    Unfortunately, when file is rendered, no changes appear.
    Did you mean by this? Or I did wrong something.

    Plugin Author Dani Llewellyn

    (@diddledani)

    First, you have $a_z_query->the_item() twice. It needs to only be used at the very beginning of the while loop. Having it twice will load the next post on the list, if there is one, before you have finished outputting the current post.

    Second, you are using $a_z_query->get_the_item_object() incorrectly. The first one assigning to $post is correct, the second one assigning to $post2 will do nothing.

    I think once you remove the second $a_z_query->the_item() the template will start working how you wanted it.

    Thread Starter F?ldesi, Mihály

    (@foldesistudio)

    Thank you Sir! You are a hero! When does new version release?

    Plugin Author Dani Llewellyn

    (@diddledani)

    The new version is out now!

    To use the metadata function you can call it like:

    <?php echo esc_html( $a_z_query->get_item_meta( 'meta-key-name', true ) );
    

    The arguments are:

    1. Meta key (string)
    2. Single value (boolean: true or false)
    • This reply was modified 5 years, 11 months ago by Dani Llewellyn. Reason: oops. named the variable wrong! should be `a_z_query`; I accidentally wrote `$a_z_listing`

    Hi, I got this working but I was wondering if it’s possible to have the letters sorted by the metadata value?

    Also I can’t get the templates to work : (

    I have two files in my template root folder:
    a-z-listing-autores.php
    a-z-listing-palavras.php

    That correspond to the slug of the pages:
    autores
    palavras

    Doesn’t work… it goes to the default template. If I remove the -section value it reads the templates and displays it correctly. any ideas?

    • This reply was modified 5 years, 9 months ago by helderluis.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Displaying Custom Fields’ is closed to new replies.