Warning: strpos(): Empty needle in /home/mobiloud/public_html/help/wp-content/plugins/sg-cachepress/core/Htaccess/Htaccess.php on line 106

Warning: Cannot modify header information - headers already sent by (output started at /home/mobiloud/public_html/help/wp-content/plugins/sg-cachepress/core/Htaccess/Htaccess.php:106) in /home/mobiloud/public_html/help/wp-content/plugins/sg-cachepress/core/Supercacher/Supercacher_Helper.php on line 46
Showing custom fields in your News app – Help & Support
  1. Home
  2. Building a News app
  3. Showing custom fields in your News app

Showing custom fields in your News app

With MobiLoud you have the ability to add any custom code to your app’s post/page layout. Just click on MobiLoud in your WordPress admin dashboard, select Settings and then click on the Editor tab.

You’ll see something like this:

MobiLoud Code Editor

 

Using the Editor, select a “PHP” position within the article screen, like “PHP after Content”. This allows you to add any PHP code and have the result shown below the main article or page contents.

Note for “PHP” spaces, you should enter PHP code directly, without the <?php opening tag.

Now to show the contents of a custom field, use the code below:

echo get_post_meta($post-&gt;ID, 'fieldname', true);

Say for example you want to include the value for a book title you’ve reviewed and include the “Title:” text before the value, while checking if the value is actually present for the current post, you’d use this code:
$title = get_post_meta( $post-&gt;ID, 'title', true );
 // check if the custom field has a value
 if( ! empty( $title ) ) {
 echo "&lt;strong&gt;Book title&lt;/strong&gt;: ".$title."&lt;br/&gt;";
 }

 

Related Articles