• Resolved tysto

    (@tysto)


    I was hoping this plugin would let me display the value in a custom field key that I specify, but it seems to only let me filter by them and display the title of the post.

    My reasoning is that my post titles have extra information that I don’t need cluttering up the list, so I have a custom field for each one with a “short title” value, but I’m having trouble finding something that lets me display that short title instead of the full post title.

    https://www.ads-software.com/plugins/wp-list-pages-by-custom-taxonomy/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author piccart

    (@piccart)

    Hello,

    I am sorry but this plugin isn’t meant for what you need.

    though, if you let me know which is the meta-field slug, I might provide directions to do a little tweak on the plugin’s code, in order to display that short title field, instead of the post title

    Plugin Author piccart

    (@piccart)

    actually, I can provide you with directions, and then you can just change the slug of the meta field into this code.

    so, first of all, you have to make a duplicate of the file that you will find here:

    wp-content/plugins/wp-list-pages-by-custom-taxonomy/templates/pbytax_template.php

    put the duplicate of that file into your theme folder.

    then edit this duplicated file and go to the line 183. you will find this:

    <a class="pbytax-post-title" href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>" title="<?php echo esc_attr( $post->post_title ); ?>"><?php echo $post->post_title ?></a>

    change that piece of code and put this piece instead:

    <a class="pbytax-post-title" href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>" title="<?php echo esc_attr( $post->post_title ); ?>"><?php echo get_post_meta($post->ID, 'YOUR-META-FIELD-SLUG', true); ?></a>

    remember to change YOUR-META-FIELD-SLUG and put the slug of your custom meta field.

    let me know if it’s what you wanted to achieve, and don’t forget to give a rating to the plugin if it’s been useful for you. ??

    cheers!

    Plugin Author piccart

    (@piccart)

    in case you are using the option to display the posts into a dropdown, instead of changing that piece of code, you have to find this piece here (line 141):

    <option value="<?php echo esc_url( get_permalink( $post->ID ) ); ?>">
          	<?php echo $post->post_title ?>
    </option>

    and replace it with this:

    <option value="<?php echo esc_url( get_permalink( $post->ID ) ); ?>">
          	<?php echo get_post_meta($post->ID, 'YOUR-META-FIELD-SLUG', true); ?>
    </option>

    cheers!

    Plugin Author piccart

    (@piccart)

    hello!

    since version 1.4.0, the code within the template file is a bit changed, so the variable $post is now

    $pbytax_post

    therefore, in all the code samples above, you should substitute $post with $pbytax_post every time you find it.

    cheers!

    this is a fantastic plugin, thank you!

    following on from the above I want to try to append a ‘price’ meta in front of the date, so that it looked something like:

    £10,000 12-06-2016

    I’m trying the below in ‘pbytax_template.php’ line 140, with my additional code shown below.

    before

    <?php if ($display_date=="yes"){
                                            ?>
                                            <div class="pbytax-meta">
                                           		<span class="pbytax-date pbytax-date-<?php echo $date_align; ?>"><?php echo get_the_date( 'd-m-Y', $pbytax_post->ID ); ?></span>
                                            </div>
                                        <?php } ?>

    after

    <?php if ($display_date=="yes"){
                                            ?>
                                            <div class="pbytax-meta">
                                           		<span class="pbytax-date pbytax-date-<?php echo $date_align; ?>"><?php echo get_post_meta($post->ID, 'price', true); echo get_the_date( 'd-m-Y', $pbytax_post->ID ); ?></span>
                                            </div>
                                        <?php } ?>

    but am not getting what I’m after.. any help would be appreciated greatly.

    kind regards

    Plugin Author piccart

    (@piccart)

    Hello!
    thanks for your great feedback and for the rating!! it’s really appreciated! ??

    since version 1.4 the above code must be tweaked because to avoid overriding the $post variable, I’m now using a custom variable for the retrieved posts object.

    so whenever you want to get something from the currently looped post, you must use $pbytax_post instead of $post.
    by instance in your code you would put:
    $pbytax_post->ID

    then it should work just fine.
    cheers!

    you are quite right, it’s written in 5th post too!
    thanks for pointing that out again =)

    works perfectly.

    thanks again for this great plugin.

    Plugin Author piccart

    (@piccart)

    hi there!

    glad you’ve managed to achieve what you need, and thanks again for your words! ??

    cheers!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display key value instead of post title’ is closed to new replies.