• Hi there,

    I am trying to use the plugin to sort posts by their customfield value (a date stored in Epoch format) and display the date.

    The custom field was created using the plugin “types” and the sorting seems to be working fine so far.

    However, I am unable to display either the custom-field’s name or the value.

    Here is the shortcode I am using:

    [catlist numberposts=-1 template=exhibitions post_type="exhibition" name="past" thumbnail='yes' thumbnail_size=thumbnail thumbnail_class="featured-thumbnail thumbnail smallest" customfield_display=wpcf-end-date customfield_display_name=yes customfield_orderby=wpcf-end-date order=asc no_posts_text="Sorry, no exhibitions were found in this category" date="yes"]

    Any help would be welcome as this has been an issue for a while.

    Cheers

    https://www.ads-software.com/plugins/list-category-posts/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi, have you tried it without specifying a custom template, just to see if the customfield is displayed in that case?

    Thread Starter benratelade

    (@benratelade)

    I tried that, and indeed, the custom field is being displayed then.

    I don’t quite understand why it is no longer showing now, as I only moved one line higher in the code, and added a few tags here and there for styling.

    Here is what I have:

    foreach ($this->catlist->get_categories_posts() as $single){
      //Start a List Item for each post:
      $lcp_display_output .= '<li class="mini-post-holder clearfix">';
    
       //Post Thumbnail
      $lcp_display_output .= $this->get_thumbnail($single);
    
      //Show the title and link to the post:
      $lcp_display_output .= "<h4>".$this->get_post_title($single)."</h4>";
    
      //Show comments:
      $lcp_display_output .= $this->get_comments($single);
    
      //Show date:
      $lcp_display_output .= ' ' . $this->get_date($single);
    
      //Show author
      $lcp_display_output .= $this->get_author($single);
    
      //Custom fields:
      $lcp_display_output .= $this->get_custom_fields($this->params['customfield_display'], $single->ID);
    
      /**
       * Post content - Example of how to use tag and class parameters:
       * This will produce:<p class="lcp_content">The content</p>
       */
      $lcp_display_output .= $this->get_content($single, 'p', 'lcp_content');
    
      /**
       * Post content - Example of how to use tag and class parameters:
       * This will produce:<div class="lcp_excerpt">The content</div>
       */
      $lcp_display_output .= $this->get_excerpt($single, 'div', 'lcp_excerpt');
    
      //Close li tag
      $lcp_display_output .= '</li>';
    }

    Any idea what I did wrong?

    Hi, I don’t think you did anything wrong.

    I’ve found a bug in the LCP version 0.51 lcp-catlistdisplayer.php code.
    In an older version which I have the get_custom_fields function used to have several parameters, the first of which was the setting of customfield_display. For some reason, the author has removed that and the function now only has the post_id as a parameter passed to it.

    For a quick fix if you change this line in your template:
    $lcp_display_output .= $this->get_custom_fields($this->params[‘customfield_display’], $single->ID);

    to
    $lcp_display_output .= $this->get_custom_fields($single->ID);

    you may find it works. Let us know, because there must be hundreds, if not thousands, of templates that are now broken.

    Just a thought, it may be sensible to leave both your old line in as well as put in the new line, just in case the author ever goes back to the old way (or you go back to an older version of the plugin).

    ***CORRECTION***

    sorry, the author has also changed the way the post id is send to get_custom_fields so your new line should be:
    $lcp_display_output .= $this->get_custom_fields($single);

    ie without the ->ID (he now picks up the info about whether customfields are to be displayed from the object, so you don’t need to send the parameters separately).

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘customfield_display not working’ is closed to new replies.