<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>

		<title>Using custom fields in recent posts &#8211; Themeco Community</title>
		<atom:link href="https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/feed/" rel="self" type="application/rss+xml" />
		<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/feed/</link>
		<description></description>
		<lastBuildDate>Sun, 12 Oct 2025 02:04:37 +0000</lastBuildDate>
		<generator>https://bbpress.org/?v=2.6.14</generator>
		<language>en-US</language>

		
														
					
				<item>
					<guid>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-183426</guid>
					<title><![CDATA[Using custom fields in recent posts]]></title>
					<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-183426</link>
					<pubDate>Thu, 15 Jan 2015 06:48:39 +0000</pubDate>
					<dc:creator>nvanhoose</dc:creator>

					<description>
						<![CDATA[
						<p>I am currently updating my site to x-theme.  Building it on another server and preparing to migrate, etc.</p>
<p>All of my blog posts on the current site have a custom field labeled &#8220;condensed-title.&#8221;  I used this on the old site when the full title was a little long.  </p>
<p>I would like to use this meta field when I employ the themes recent posts shortcode in certain cases.  Is this possible?  For instance, when I use the recent posts shortcode in the sidebar, some of my posts have titles that are just too long and look bad.  The &#8220;condensed-title&#8221; I&#8217;ve already made for all of the posts would be perfect.</p>
<p>Thanks for your help!!!</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-183778</guid>
					<title><![CDATA[Reply To: Using custom fields in recent posts]]></title>
					<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-183778</link>
					<pubDate>Thu, 15 Jan 2015 17:15:19 +0000</pubDate>
					<dc:creator>nvanhoose</dc:creator>

					<description>
						<![CDATA[
						<p>The way I accomplish this right now is as such:</p>
<pre><code>&lt;ul&gt;
&lt;?php while (have_posts()): the_post(); ?&gt;
&lt;li&gt;&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;&lt;?php the_post_thumbnail( &#039;list-thumb&#039; ); ?&gt;&lt;/a&gt;
&lt;b&gt;&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;&lt;?php echo get_post_meta($post-&gt;ID, &#039;condensed_title&#039;, true); ?&gt;&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;
&lt;p&gt;&lt;?php echo get_the_other_excerpt(); ?&gt;&lt;span&gt;&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;more &#187;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;
&lt;?php endwhile; ?&gt;
&lt;/ul&gt;</code></pre>
<p>Obviously not very elegant but it worked.  With all the functions going on in this theme, I can&#8217;t make heads or tails of where or how to call up that alternate, shorter title&#8230;</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-183792</guid>
					<title><![CDATA[Reply To: Using custom fields in recent posts]]></title>
					<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-183792</link>
					<pubDate>Thu, 15 Jan 2015 17:38:55 +0000</pubDate>
					<dc:creator>nvanhoose</dc:creator>

					<description>
						<![CDATA[
						<p>Hey guys,</p>
<p>So I basically got this working by changing the relevant line in functions.php to </p>
<p><code>. &#039;&lt;h3 class=&quot;h-recent-posts&quot;&gt;&#039; . get_post_meta(get_the_ID(), &#039;custom-field-title, true ) . &#039;&lt;/h3&gt;&#039;</code></p>
<p>which is referenced in another thread.  It would be nice to be able to trigger this action with something in the shortcode like shortened-title=yes&#8230; but for now is working great.  Thanks.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-183816</guid>
					<title><![CDATA[Reply To: Using custom fields in recent posts]]></title>
					<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-183816</link>
					<pubDate>Thu, 15 Jan 2015 18:10:07 +0000</pubDate>
					<dc:creator>Zeshan</dc:creator>

					<description>
						<![CDATA[
						<p>Hi there,</p>
<p>Thanks for writing in!</p>
<p>Because this requires a template change, I&#8217;d advise that you setup a <a href="http://theme.co/x/member/kb/how-to-setup-child-themes/" title="Child Themes" target="_blank" rel="nofollow">child theme</a>. This allows you to make code changes that won&#8217;t be overwritten when an <strong>X</strong> update is released. After your child theme is setup, please review how we recommend making template changes in <a href="http://theme.co/x/member/kb/customization-best-practices/" rel="nofollow">Customization Best Practices</a>.</p>
<p>After that, add following code in your child theme&#8217;s <strong>functions.php</strong> file:</p>
<pre><code>function x_shortcode_recent_posts2( $atts ) {
  extract( shortcode_atts( array(
    &#039;id&#039;          =&gt; &#039;&#039;,
    &#039;class&#039;       =&gt; &#039;&#039;,
    &#039;style&#039;       =&gt; &#039;&#039;,
    &#039;type&#039;        =&gt; &#039;&#039;,
    &#039;count&#039;       =&gt; &#039;&#039;,
    &#039;category&#039;    =&gt; &#039;&#039;,
    &#039;offset&#039;      =&gt; &#039;&#039;,
    &#039;orientation&#039; =&gt; &#039;&#039;,
    &#039;no_image&#039;    =&gt; &#039;&#039;,
    &#039;fade&#039;        =&gt; &#039;&#039;
  ), $atts ) );

  $id            = ( $id          != &#039;&#039;          ) ? &#039;id=&quot;&#039; . esc_attr( $id ) . &#039;&quot;&#039; : &#039;&#039;;
  $class         = ( $class       != &#039;&#039;          ) ? &#039;x-recent-posts cf &#039; . esc_attr( $class ) : &#039;x-recent-posts cf&#039;;
  $style         = ( $style       != &#039;&#039;          ) ? &#039;style=&quot;&#039; . $style . &#039;&quot;&#039; : &#039;&#039;;
  $type          = ( $type        == &#039;portfolio&#039; ) ? &#039;x-portfolio&#039; : &#039;post&#039;;
  $count         = ( $count       != &#039;&#039;          ) ? $count : 3;
  $category      = ( $category    != &#039;&#039;          ) ? $category : &#039;&#039;;
  $category_type = ( $type        == &#039;post&#039;      ) ? &#039;category_name&#039; : &#039;portfolio-category&#039;;
  $offset        = ( $offset      != &#039;&#039;          ) ? $offset : 0;
  $orientation   = ( $orientation != &#039;&#039;          ) ? &#039; &#039; . $orientation : &#039; horizontal&#039;;
  $no_image      = ( $no_image    == &#039;true&#039;      ) ? $no_image : &#039;&#039;;
  $fade          = ( $fade        == &#039;true&#039;      ) ? $fade : &#039;false&#039;;

  $output = &quot;&lt;div {$id} class=\&quot;{$class}{$orientation}\&quot; {$style} data-fade=\&quot;{$fade}\&quot;&gt;&quot;;

    $q = new WP_Query( array(
      &#039;orderby&#039;          =&gt; &#039;date&#039;,
      &#039;post_type&#039;        =&gt; &quot;{$type}&quot;,
      &#039;posts_per_page&#039;   =&gt; &quot;{$count}&quot;,
      &#039;offset&#039;           =&gt; &quot;{$offset}&quot;,
      &quot;{$category_type}&quot; =&gt; &quot;{$category}&quot;
    ) );

    if ( $q-&gt;have_posts() ) : while ( $q-&gt;have_posts() ) : $q-&gt;the_post();

      if ( $no_image == &#039;true&#039; ) {
        $image_output       = &#039;&#039;;
        $image_output_class = &#039;no-image&#039;;
      } else {
        $image_output       = &#039;&lt;div class=&quot;x-recent-posts-img&quot;&gt;&#039; . get_the_post_thumbnail( get_the_ID(), &#039;entry-cropped&#039;, NULL ) . &#039;&lt;/div&gt;&#039;;
        $image_output_class = &#039;with-image&#039;;
      }

      $output .= &#039;&lt;a class=&quot;x-recent-post&#039; . $count . &#039; &#039; . $image_output_class . &#039;&quot; href=&quot;&#039; . get_permalink( get_the_ID() ) . &#039;&quot; title=&quot;&#039; . esc_attr( sprintf( __( &#039;Permalink to: &quot;%s&quot;&#039;, &#039;__x__&#039; ), the_title_attribute( &#039;echo=0&#039; ) ) ) . &#039;&quot;&gt;&#039;
                 . &#039;&lt;article id=&quot;post-&#039; . get_the_ID() . &#039;&quot; class=&quot;&#039; . implode( &#039; &#039;, get_post_class() ) . &#039;&quot;&gt;&#039;
                   . &#039;&lt;div class=&quot;entry-wrap&quot;&gt;&#039;
                     . $image_output
                     . &#039;&lt;div class=&quot;x-recent-posts-content&quot;&gt;&#039;
                       . &#039;&lt;h3 class=&quot;h-recent-posts&quot;&gt;&#039; . (($v = get_post_meta(get_the_ID(), &#039;condensed_title&#039;, true)) ? $v : get_the_title()) . &#039;&lt;/h3&gt;&#039;
                       . &#039;&lt;span class=&quot;x-recent-posts-date&quot;&gt;&#039; . get_the_date() . &#039;&lt;/span&gt;&#039;
                     . &#039;&lt;/div&gt;&#039;
                   . &#039;&lt;/div&gt;&#039;
                 . &#039;&lt;/article&gt;&#039;
               . &#039;&lt;/a&gt;&#039;;

    endwhile; endif; wp_reset_postdata();

  $output .= &#039;&lt;/div&gt;&#039;;

  return $output;
}

add_filter(&#039;init&#039;, &#039;custom_recents_posts&#039;);

function custom_recents_posts() {
   remove_shortcode( &#039;recent_posts&#039; );

   add_shortcode( &#039;recent_posts&#039;, &#039;x_shortcode_recent_posts2&#039; );
}
</code></pre>
<p>Hope this helps. 🙂</p>
<p>Thank you.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-337543</guid>
					<title><![CDATA[Reply To: Using custom fields in recent posts]]></title>
					<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-337543</link>
					<pubDate>Thu, 23 Jul 2015 00:20:01 +0000</pubDate>
					<dc:creator>troydesh</dc:creator>

					<description>
						<![CDATA[
						<p>I am trying to do something very similar. I tried modifying this solution, but couldn&#8217;t quite figure it out.</p>
<p>I&#8217;d like to do is add data from the portfolio custom field called &#8220;role&#8221; just below the post tile (in place of date) when using the recent_posts shortcode</p>
<p>It would also be fantastic if I could add a custom button to display below that custom field data. I could potentially use the Project Link field for the data. Or would a separate custom field be best?<br />
Just not sure how to implement into shortcode.</p>
<p>So when using recent_posts shortcode it would display:</p>
<p>Image<br />
Post Title<br />
Role<br />
Button </p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-337685</guid>
					<title><![CDATA[Reply To: Using custom fields in recent posts]]></title>
					<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-337685</link>
					<pubDate>Thu, 23 Jul 2015 03:05:54 +0000</pubDate>
					<dc:creator>Rue Nel</dc:creator>

					<description>
						<![CDATA[
						<p>Hello There,</p>
<p>Thanks for updating this thread! </p>
<p>Please make use of the custom field instead. For more details on how to use custom fields, please check it out here: <a href="https://codex.wordpress.org/Custom_Fields" rel="nofollow">https://codex.wordpress.org/Custom_Fields</a></p>
<p>To display it in the custom recent posts element, please make sure that you do have a child theme installed. You can then insert this code in your child theme&#8217;s functions.php file</p>
<pre><code>function x_shortcode_recent_posts2( $atts ) {
  extract( shortcode_atts( array(
    &#039;id&#039;          =&gt; &#039;&#039;,
    &#039;class&#039;       =&gt; &#039;&#039;,
    &#039;style&#039;       =&gt; &#039;&#039;,
    &#039;type&#039;        =&gt; &#039;&#039;,
    &#039;count&#039;       =&gt; &#039;&#039;,
    &#039;category&#039;    =&gt; &#039;&#039;,
    &#039;offset&#039;      =&gt; &#039;&#039;,
    &#039;orientation&#039; =&gt; &#039;&#039;,
    &#039;no_image&#039;    =&gt; &#039;&#039;,
    &#039;fade&#039;        =&gt; &#039;&#039;
  ), $atts ) );

  $id            = ( $id          != &#039;&#039;          ) ? &#039;id=&quot;&#039; . esc_attr( $id ) . &#039;&quot;&#039; : &#039;&#039;;
  $class         = ( $class       != &#039;&#039;          ) ? &#039;x-recent-posts cf &#039; . esc_attr( $class ) : &#039;x-recent-posts cf&#039;;
  $style         = ( $style       != &#039;&#039;          ) ? &#039;style=&quot;&#039; . $style . &#039;&quot;&#039; : &#039;&#039;;
  $type          = ( $type        == &#039;portfolio&#039; ) ? &#039;x-portfolio&#039; : &#039;post&#039;;
  $count         = ( $count       != &#039;&#039;          ) ? $count : 3;
  $category      = ( $category    != &#039;&#039;          ) ? $category : &#039;&#039;;
  $category_type = ( $type        == &#039;post&#039;      ) ? &#039;category_name&#039; : &#039;portfolio-category&#039;;
  $offset        = ( $offset      != &#039;&#039;          ) ? $offset : 0;
  $orientation   = ( $orientation != &#039;&#039;          ) ? &#039; &#039; . $orientation : &#039; horizontal&#039;;
  $no_image      = ( $no_image    == &#039;true&#039;      ) ? $no_image : &#039;&#039;;
  $fade          = ( $fade        == &#039;true&#039;      ) ? $fade : &#039;false&#039;;

  // Your custom fields
  $field1 = get_post_meta( get_the_ID(), &#039;custom-field-1-name&#039;, true );
  $field2 = get_post_meta( get_the_ID(), &#039;custom-field-2-name&#039;, true );

  $output = &quot;&lt;div {$id} class=\&quot;{$class}{$orientation}\&quot; {$style} data-fade=\&quot;{$fade}\&quot;&gt;&quot;;

    $q = new WP_Query( array(
      &#039;orderby&#039;          =&gt; &#039;date&#039;,
      &#039;post_type&#039;        =&gt; &quot;{$type}&quot;,
      &#039;posts_per_page&#039;   =&gt; &quot;{$count}&quot;,
      &#039;offset&#039;           =&gt; &quot;{$offset}&quot;,
      &quot;{$category_type}&quot; =&gt; &quot;{$category}&quot;
    ) );

    if ( $q-&gt;have_posts() ) : while ( $q-&gt;have_posts() ) : $q-&gt;the_post();

      if ( $no_image == &#039;true&#039; ) {
        $image_output       = &#039;&#039;;
        $image_output_class = &#039;no-image&#039;;
      } else {
        $image_output       = &#039;&lt;div class=&quot;x-recent-posts-img&quot;&gt;&#039; . get_the_post_thumbnail( get_the_ID(), &#039;entry-cropped&#039;, NULL ) . &#039;&lt;/div&gt;&#039;;
        $image_output_class = &#039;with-image&#039;;
      }

      $output .= &#039;&lt;a class=&quot;x-recent-post&#039; . $count . &#039; &#039; . $image_output_class . &#039;&quot; href=&quot;&#039; . get_permalink( get_the_ID() ) . &#039;&quot; title=&quot;&#039; . esc_attr( sprintf( __( &#039;Permalink to: &quot;%s&quot;&#039;, &#039;__x__&#039; ), the_title_attribute( &#039;echo=0&#039; ) ) ) . &#039;&quot;&gt;&#039;
                 . &#039;&lt;article id=&quot;post-&#039; . get_the_ID() . &#039;&quot; class=&quot;&#039; . implode( &#039; &#039;, get_post_class() ) . &#039;&quot;&gt;&#039;
                   . &#039;&lt;div class=&quot;entry-wrap&quot;&gt;&#039;
                     . $image_output
                     . &#039;&lt;div class=&quot;x-recent-posts-content&quot;&gt;&#039;
                       . &#039;&lt;h3 class=&quot;h-recent-posts&quot;&gt;&#039; . (($v = get_post_meta(get_the_ID(), &#039;condensed_title&#039;, true)) ? $v : get_the_title()) . &#039;&lt;/h3&gt;&#039;
                       . &#039;&lt;span class=&quot;x-recent-posts-date&quot;&gt;&#039; . get_the_date() . &#039;&lt;/span&gt;&#039;
                       . &lt;span class=&quot;custom-class field1&quot;&gt;&#039; . $field1 . &#039;&lt;/span&gt;
                       . &lt;span class=&quot;custom-class field2&quot;&gt;&#039; . $field2 . &#039;&lt;/span&gt;
                     . &#039;&lt;/div&gt;&#039;
                   . &#039;&lt;/div&gt;&#039;
                 . &#039;&lt;/article&gt;&#039;
               . &#039;&lt;/a&gt;&#039;;

    endwhile; endif; wp_reset_postdata();

  $output .= &#039;&lt;/div&gt;&#039;;

  return $output;
}
add_filter(&#039;init&#039;, &#039;custom_recents_posts&#039;);

function custom_recents_posts() {
   remove_shortcode( &#039;recent_posts&#039; );
   add_shortcode( &#039;recent_posts&#039;, &#039;x_shortcode_recent_posts2&#039; );
}</code></pre>
<p>As this is all custom development, regretfully we won’t be able to assist further. Custom development is outside the scope of our support. We’re happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation.</p>
<p>Thank you for your understanding.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-338313</guid>
					<title><![CDATA[Reply To: Using custom fields in recent posts]]></title>
					<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-338313</link>
					<pubDate>Thu, 23 Jul 2015 15:37:38 +0000</pubDate>
					<dc:creator>troydesh</dc:creator>

					<description>
						<![CDATA[
						<p>I appreciate your help on this. For some reason this code results in an error though<br />
Parse error: syntax error, unexpected &#8216;&lt;&#8216;</p>
<p> in this line of functions.php in my child theme:</p>
<p>. &lt;span class=&#8221;custom-class field1&#8243;&gt;&#8217; . $role . &#8216;&lt;/span&gt;</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-338646</guid>
					<title><![CDATA[Reply To: Using custom fields in recent posts]]></title>
					<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-338646</link>
					<pubDate>Thu, 23 Jul 2015 21:07:40 +0000</pubDate>
					<dc:creator>Rad</dc:creator>

					<description>
						<![CDATA[
						<p>Hi there,</p>
<p>There are missing single quotes. Should be like this,</p>
<pre><code>                       . &#039;&lt;span class=&quot;custom-class field1&quot;&gt;&#039; . $field1 . &#039;&lt;/span&gt;&#039;
                       . &#039;&lt;span class=&quot;custom-class field2&quot;&gt;&#039; . $field2 . &#039;&lt;/span&gt;&#039;</code></pre>
<p>Cheers!</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-659890</guid>
					<title><![CDATA[Reply To: Using custom fields in recent posts]]></title>
					<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-659890</link>
					<pubDate>Tue, 10 Nov 2015 17:57:44 +0000</pubDate>
					<dc:creator>DoebankDesigns</dc:creator>

					<description>
						<![CDATA[
						<p>I&#8217;m trying to use this code to display two custom fields instead of the post date, but I can&#8217;t seem to get it to work. Any ideas?</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-660140</guid>
					<title><![CDATA[Reply To: Using custom fields in recent posts]]></title>
					<link>https://theme.co/archive/forums/topic/using-custom-fields-in-recent-posts/#post-660140</link>
					<pubDate>Tue, 10 Nov 2015 20:52:50 +0000</pubDate>
					<dc:creator>Nabeel A</dc:creator>

					<description>
						<![CDATA[
						<p>Hi there,</p>
<p>Thanks for writing in! You&#8217;ll need to add the above code in your <strong>child theme’s functions.php</strong> file. Can you please provide us the URL of your site so we can take a look at your current setup?</p>
<p>Thanks!</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

