Jump to content

Archived

This topic is now archived and is closed to further replies.

bfrye26

Custom Fields Display with DMS

Recommended Posts

bfrye26

Looking to display custom fields in DMS although seem to be having no luck. I am using Advanced Custom Fields but I can not seem to find where I would need to add the custom code to display the needed information. Trying to add them to my review page. Any help people can provide would be amazing!

Share this post


Link to post
Share on other sites
Rob

I can't imagine that there should be any difficulty as the use of custom post fields is done via WordPress, not DMS.   As long as they're properly set up in the WP postloop, then they'll display in DMS provided the Content/Postloop is called on the page.

 

What is the support for the plugin saying about working in WP 3.6?


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
bfrye26

Rob See the issue is they need to be setup in the themes post loop. The code for them has to be added to the post loop display to have it include the needed fields

 

It is easy to do in most templates sadly it is not so easy with DMS since I am unsure on what files to change

 

any suggestions would be amazing!

Share this post


Link to post
Share on other sites
Rob

Honestly, this is a programmer question, and I'm hardly a programmer.  This explains some things http://codex.wordpress.org/Custom_Fields but essentially, as far as I know, the custom fields should display in the post loop and we just pull it, not excluding anything in the post loop, that I know about.

 

Have you tried some of the plugins out there that help with creating/adding custom fields?

 

I'm going to reference this to our developers and ask them to chime in.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
bfrye26

Rob Thanks for the help. I have already made the custom fields it is now about displaying them. 

Share this post


Link to post
Share on other sites
Rob

Excellent news. 


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
Rob

My mistake.  Please forgive me  I'll speak to our developer and find out how this is done.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
clinton4

bfrye26

 

I have the same issue here http://forum.pagelines.com/topic/29166-custom-page-template/

 

I am guessing you also expected to add code like this..

<?php $mycustomfield = get_post_meta($post->ID, 'mycustomfield', true); ?>
<?php echo $mycustomfield; ?>

.. or ..

<?php the_field($field_name, $post_id); ?>

.. to your custom page template.

 

But as i understad, files like page.php and single.php only contains the fuction setup_pagelines_template();. So there is no html/php code where you could put in your php code to display the custom field.

 

As you see in the post i linked to above, i guess you need to find a plugin which alows you to use a short code which fetches the custom fields data and display it within the page's content (visual editor).

 

Rob

 

It would be greate to get an answer from somebody who knows php coding.

Share this post


Link to post
Share on other sites
Rob

Are you familiar with hooks?

 

add_action( 'the_content', 'add_some_field' );
function some_field() {
     the_field( "text_field" );
}

function add_some_field()

 

This is what I'm told will work. However, I'm totally unclear how it's executed.

 

That said, there's a plugin called Shortcode Exec PHP that would take the PHP you quoted earlier, and let you convert it to a simple shortcode.  Then, you could paste the shortcode into DMS in a textarea.   Worth a try and doesn't cost anything.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
clinton4

Yes, hooks would work. But it's a bit more cumbersome to work with. At least in my opinion.

Share this post


Link to post
Share on other sites
bfrye26

clinton4"] @[member="Rob, I only really need it for 3 sections on my site so really just a matter of sorting out how to use the hook to make it work. Does anyone have any ideas how this could be done? I am new to using hooks

Share this post


Link to post
Share on other sites
Erwan

bfrye26 cc @clinton4 @Rob
 

For basic needs, in order to display some custom fields, when PHP is required and there's no shortcode available (as far as I'm aware, ACF for instance only provides the basic [acf field="field_name" post_id="xxx"]), and I don't want to play with hooks / create shortcodes / create templates / etc.:

I just use the "Allow PHP in Posts and Pages" plugin. Referring to ACF, Types or whatever APIs, I just put the PHP in a post, a page, or a DMS TextBox, and that's it!

Maybe it could help you?

Share this post


Link to post
Share on other sites
clinton4
Erwan

After a good night sleep, I am clear in my head again. What i wrote about using a short code in the posts/pages content, would not be dynamically and it would be easier to just put the data right in the post/pege itself.

In most cases (maby all cases), custom field data is used to handle dynamically data. So it must be used/added with PHP somewhere.

Only solution I can see, is using hooks.

I am not sure how to handle it with hooks, but I will post a solution when i find one myself. It will be something like Rob mentioned above.

Share this post


Link to post
Share on other sites
Erwan

clinton4

The plugin I mentioned (it's not the ony one, but is DMS friendly: pages/posts/TextBoxes/etc.) handles data dynamically: you can use whatever PHP you wan't with it.

I use it for basic needs, even when I use hooks or create sections,etc.

Share this post


Link to post
Share on other sites
Erwan

NP. Tell me later if you find it it useful.

Btw I use it A LOT for other APIs 
such as s2Member when I'm lazy ;)

Esp. in TextBoxes (aka Content Boxes in v2 - Framework). Didn't try yet in other boxes such as MediaBoxes or iBoxes, no reason it should not work.

Share this post


Link to post
Share on other sites
bfrye26

Erwan"] @[member="clinton4 after some testing I can not seem to get this to work for me. It seems when the calls are made outside of the loop it will not carry the data. Looking for solutions

Share this post


Link to post
Share on other sites
clinton4

Struggling with the same problem. 

 

Try adding

 

global $post;

 

on top of your code.

 

Let me know if it solves the problem :)

Share this post


Link to post
Share on other sites
bfrye26

clinton4

 

No dice for me, what code have you tried that worked? Maybe I am missing something I should have in place

Share this post


Link to post
Share on other sites
clinton4

bfrye26

 

My goal is to create a function which alows me to make custom page templates simular to the codex way.

 

Not sure how you plan to deal with it. But I am trying to create a filter hook which works like this:

 

- If a custom field with the key "customPageTemplate" is set on a page, it should not return the $content in the loop, but insted include and return the content from the file mycustomtemplate.php. This file is similar to the examples on http://codex.wordpress.org/Page_Templates#Examples

 

- If the custom field above is not set, it should return the $content as normal.

 

Here is what i got so far:

<?php

function custom_page_template($content) {

	global $post;
	
	// $customPageTemplate = mycustomtemplate.php
	$customPageTemplate = get_post_meta($post->ID, 'customPageTemplate', true);
	
	if( !empty($customPageTemplate) ) {
		
		return include(get_theme_root().'/'.get_stylesheet().'/'.$customPageTemplate);
	
	}
	
	else {

		return $content;
	}

}

add_filter( 'the_content', 'custom_page_template' );

?>

I needed to add the global $post; because the global variables was not present.

 

But my function is not working the way i want it to work, so i will let you if and when i get it to work.

Share this post


Link to post
Share on other sites
bfrye26

clinton4 sounds good! Who would have thought just getting them to display would be so tedious!

Share this post


Link to post
Share on other sites
clinton4

There is another solution mentioned somewhere in the forums.

 

Something like this:

 

- Get a wordpress plugin that allows you to use PHP code inside post/pages/dms-sections.

- Create the layout you want using TextBox where you want custom fields to appear.

- Insert your PHP code inside this TextBox to display your custom field data there.

- Assign your layout to the page.

 

For me that is not an option, but for most people it might be okay.

Share this post


Link to post
Share on other sites
bfrye26

ya, sadly this will not work with me either. It is sad it can not

Share this post


Link to post
Share on other sites
Erwan

Erwan"] @[member="clinton4 after some testing I can not seem to get this to work for me. It seems when the calls are made outside of the loop it will not carry the data. Looking for solutions


bfrye26

Here's an example of how you can display with PHP an ACF custom field referring to a post in a TextBox placed on a static home page (i.e. "outside of any post loop"), using the plugin mentioned above: screenshot.




 

Share this post


Link to post
Share on other sites

×