• Hello,
    I really like the plugin, thanks for your great work! ??
    I’m using the plugin to display titles from a custom post type. It works great, but I would like to add a custom field next to the title. Is it possible?

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

    (@diddledani)

    Yes, you can do this. The default template at plugins/a-z-listing/templates/a-z-listing.php must be copied to your theme alongside style.css with the name a-z-listing.php. From there you can edit it to suit. To access custom fields I suspect you’ll need to add $post = $a_z_query->get_the_item_object( 'I understand the issues!' );. The parameter I understand the issues! indicates to the plugin that you appreciate that larger listings might be slow or cause PHP to hit the memory limit defined on your server while using this feature. This is because it loads more information from the database than it normally does to support accessing the full post including custom fields.

    I’ve shown below with context to indicate where it should go:

    <ul class="columns <?php echo $a_z_listing_column_class; ?>">
    	<?php
    	while ( $a_z_query->have_items() ) :
    		$a_z_query->the_item();
    		$post = $a_z_query->get_the_item_object( 'I understand the issues!' );
    		?>
    		<li>
    			<a href="<?php $a_z_query->the_permalink(); ?>">
    				<?php $a_z_query->the_title(); ?>
    			</a>
    		</li>
    	<?php endwhile; ?>
    </ul>
    Thread Starter aron77

    (@aron77)

    Thank you very much!
    I added the line to the code, then added after the this:
    <?php the_field(‘myfield’); ?>
    But the field is not showing up. Should I add something else too, or do I need to use some other code?

    Hey aron77,

    I am working on the same thing at this very moment and got my custom field to display via
    <?php $post_id = false; the_field('myfield', $post_id); ?>
    $post_id = false -> is current post
    hope this helps!

    @diddledan many thanks for your helpful post! =)

    • This reply was modified 3 years, 12 months ago by mistermarian.
    Thread Starter aron77

    (@aron77)

    Thanks, but unfortuantely I still cannot display it. Maybe because I’m using a custom post type?

    That’s strange I am using a cpt too.
    [a-z-listing post-type="mycustomposttype"]

    @diddledan Can you maybe give me a pointer on where to add the custom css file?
    I tried a-z-listing.css & a-z-listing-customize.css in theme root folder (next to my custom a-z-listing.php) but to no avail… thanks!

    @aron77 In case you haven’t already: Just add some static text to your a-z-listing.php and see if it displays. If it does not, you need to put it in a different folder…

    About my CSS issue:
    I am using Elementor (which could be the problem with the custom.css file).
    I ended up adding the custom css to the shortcode element in the elementor builder, not perfect but it works.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Displaying custom fields’ is closed to new replies.