Jump to content


Photo

Display custom meta from custom post types?

CPT Custom Post Types Meta

  • Please log in to reply
18 replies to this topic

#1 jasonkadlec

jasonkadlec

    Advanced Member

  • Members

  • 32 posts
  • Country: Country Flag

Posted 01 August 2013 - 11:18 PM

I'm hoping to use PageLines to make sites, but I need sites to have some Custom Post Types and for those Custom Post Types to have post_meta (aka custom fields).

 

Now normally, I'd build a page and at some point I'd use:

 
<?php echo get_post_meta($postid, 'dtf_merch_description', true);?>

How do I now use the DMS to get/display something stored as custom meta to a post, or CPT? 

 

I was hoping I could click on the "Custom Code" button but that is just for HTML and Javascript.

 

If I've got to actually go in and make a template file like I would oldschool style... not too sure what the point is...  I may as well just code up the whole site no?

 

Or how do I make my own Section - and could I start it off with a QueryPosts loop so I'm fetching and displaying what I want from my CPT / custom post meta?

 

thanks (though I'll be SHOCKED) if this post ever gets answered judging by all the posts everywhere. ha ha.



#2 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 02 August 2013 - 12:57 PM

Jason,

 

Custom Post types and meta info should be within WordPress, in the post loop.  We're only pulling the post loop, not constructing it.  We'll lay out what the post loop delivers, but it has to be in the post loop for that to happen.   Displaying the custom fields should be easy enough.

 

Thus I'd say that the easiest way to accomplish this would be to use a plugin for creating custom post types and queries in WordPress.



#3 jasonkadlec

jasonkadlec

    Advanced Member

  • Members

  • 32 posts
  • Country: Country Flag

Posted 02 August 2013 - 04:31 PM

@Rob - that makes sense -- so it's a blend -- still some same old work in making .php files, but most stuff in the drag and drop.

 

So lets say I make a file called  foo-loop.php and this file contains my loop via a query posts and it's got all its custom meta displaying just how I want.

 

How do I then select foo-loop.php from the Pagelines DMS to drop it into the page where I want it?

 

Follow up question -- I am thinking of it this way, because I'm not going to just have 1 post loop - so I can't just edit the one post loop Pagelines has

 

I'm going to need foo-loop.php on site.com/foo-page, and I'm going to need bar-loop.php on site.com/bar

 

 

Follow up question - I read somewhere in the literature that pagelines is Bootstrap based - but I didn't see span12's or row-fluids when I did inspect element. 

 

Can I create my layout in foo-loop.php using Bootstrap scaffolding - or do I need to include the bootstrap css in the header.php?


Edited by jasonkadlec, 02 August 2013 - 04:37 PM.


#4 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 02 August 2013 - 04:43 PM

Jason,

 

I think you're going about this as if it was a theme (and doing it right, were that the case), but DMS isn't a theme. So, the key is just to built everything into WP, in the post loop.  Now that means also adding classes with unique names where possible, so you can style them in DMS later.  But calling the custom post types, taxonomies and meta shouldn't be a problem if it's in the postloop as we already do that.

 

The key is going to be how these fields look once they're displayed, and those custom classes will help you write CSS to make them look as desired.

 

You likely need something like: http://wordpress.org/plugins/types/



#5 jasonkadlec

jasonkadlec

    Advanced Member

  • Members

  • 32 posts
  • Country: Country Flag

Posted 02 August 2013 - 06:21 PM

I think I'm lost... as I don't really see a file called loop.php in the default DMS theme, and I'm not sure you mean I need to edit something, or make a child theme or just how to:

 

"build everything into WP, in the post loop" 

 

Backing up --

 

Lets say I've got the Types plugin and I've 2 custom post types, and assigned 5 custom fields to each.

 

So there is  Post Type Foo with Foo-Fields1-5   and there is Post Type Bar with Fields Bar1-5.

 

Are you saying a)

 

I don't have to edit any of the DMS files to make Foo-Fields 1-5 and Bar Fields 1-5 appears some where? 

 

That DMS will just output everything? If so, that's not what I'm seeing... I'm looking at 

 

mysite.com/foo/foo-post-1 

 

and I'm only seeing The Title and The Content ( the_title(); and the_content(); ) -- I'm not seeing any of the other custom fields out put?

 

 

Or are you saying b:

 

If I want to get those fields to show up, I *do* need to edit (or create ) a file in the DMS theme folder.

 

If so, what file in the DMS theme do I need to edit to get those fields to display along with the default title and content, or what file can I add?

 

My guess is editing a file like class.posts is *not* the way to go -- seems like that is "core DMS" -- so there needs to be a child theme right?

 

Can I just create a file called loop.php and DMS will know what to do with it?

 

Thanks for the quick answers! If I can solve this ( and I'm sure EVERYONE who has already built a site using Custom Post Types) will be able to use this thread to "get it" and switch over to the bad-assness that is DMS!!! 

 

I can't wait!!



#6 jasonkadlec

jasonkadlec

    Advanced Member

  • Members

  • 32 posts
  • Country: Country Flag

Posted 02 August 2013 - 06:50 PM

Hmm starting to make more sense after reading:

 

http://nichola.us/th...with-pagelines/

 

So... I can create a child theme, make some custom sections and those sections can be programmed as granular as need be -- 

 

For example, can I just create a section called "Foo-Field 1" and put in there:

 
<div class="button">
  <a class="button" href="<?php echo get_post_meta($postid, 'foo_field_1', true);?>">Buy Now</a>
</div>


Then,

 

Anywhere I need a button to show up - I can just then drag this "section" into the theme ( assuming I'm dragging it into a page that is a custom post type that has the custom field foo_field_1 in it?



#7 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 04 August 2013 - 03:52 PM

I don't know about dragging, but you can add the button with shortcode which calls that php as a link.

 

And again, DMS isn't a theme.  It's a Document Management System. We've gone well past themes back in 2011.

 

You may want to see our Tools http://demo.pagelines.me/tools to find the variety of buttons you can use with shortcodes, that can be placed in any text field or text area.



#8 jasonkadlec

jasonkadlec

    Advanced Member

  • Members

  • 32 posts
  • Country: Country Flag

Posted 04 August 2013 - 06:53 PM

Rob:

 

I didn't see a shortcode to add a button that would pull content from a custom field? 

 

For all those who are are following this thread, making the mental jump from theme to DMS -- 

 

(and Rob please correct me if I'm wrong)

 

Here is my use case -- the client has a custom store because it uses buy buttons from a 3rd party e-commerce solution. 

 

The client pastes in the "buy button code" - and then his theme takes care of displaying that on two pages - a kind of product over view page, and then the product details page.

 

This is also done via a custom post type called "products." 

 

The challenge is to use PageLines to overhaul this old theme, and still have a product overview page and still have a product detail page, and to NOT require re-entering all the buy buttons that are already stored with the various "product" posts.

 

doing research, it appears that there are two ways to go -- both involve creating a child theme -- so there is still theming and coding involved.

 

 

Option 1 -- create a section for the whole unit of content that displays the product title, image and buy button together on the page that shows all products. 

 

Create another section that creates the unit of content that displays everything for the details page.

 

Then create a DMS template page for the all products display, and create a DMS template page for the product details page.

 

Add the sections into both those pages - since the rest of the site is the usual header, footer, sidebar etc that doesn't have anything to do with the custom post type or custom meta fields.

 

 

Option 2 ( I think) - would be to create a section for each of the custom meta fields that a custom post type has.

 

Go about creating the page template for the product overview page, and create the page view for the product details page.

 

Drag the section containing each element into the layout as needed. 

 

The benefit is if one of those elements is needed in some new layout later, it could be just dragged into place as a section.

 

 

I've not had a chance to test out either option - but the one thing that needs some figuring out (maybe) is how to make sure the loop is going to display content from the custom post type vs. just regular posts.

 

I'm guessing a little pre_get_posts script might need to be added to the child theme's functions.php -- that instructs the loop;

 

{ pseudo code } - If you are on page  /foo  -- then get posts from the custom post type foo {/ pseudo code } 

 

 

I'm still learning my way around the whole idea of PageLines so massive appreciation to Rob for hanging in with this thread and clarifying things.

 

Also - for those who are making things with custom post types and custom fields -- I used to code it all in via the functions.php... but I have just done a site with the Types plugin - and have to say, I won't be coding up any custom post types or custom fields again ever, I'm going to use Types from here on out. 

 

I've tested Types out with PageLines and an addon from PageLines called AnyLoop and everything worked.... except AnyLoop only displays the CPT post headline, featured image and excerpt. 

 

Again.. it would be beautiful to have some feature like AnyLoop that could also detect if you've got cutom fields, and let you select which of the custom fields you want to display, and where.

 

Very, very cool stuff !! I'm going to be building my first DMS based site this month!!

 

It's going to feel like cheating to not have to write all the HTML, CSS and PHP !! 



#9 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 05 August 2013 - 05:32 PM

From everything you're telling me here, which is a bit overwhelming as I'm not a developer, it seems that all you want to do is implement an ecommerce solution, without the need to create custom post types, taxonomies, queries, etc.  It sounds like you're trying to reinvent the wheel.

 

Buttons, don't pull things.  They provide the opportunity to take an action.  That can be to process something (POST function) or call something (GET function).  To simplify that, you have a button on a form to submit info, that's a POST action, because it posts your info somewhere to a database.  If you have a button to display a list of products,  that's a GET call, because it's going to get the list and display it.

 

It seems very complex to build an ecommerce solution when there are so many out there your client may like.  For example, WooCommerce, Jigo, Ecwid or CartPress (all available from WordPress.org) and all free, though they all have premium add-ons that do special things.

 

One thing you may not have considered is the gateway to payment processing, and all those plugins have that done.   I'd suggest you download all of them and test them on a development server and present your client with the best solution for their needs.  It's going to be much, much easier.



#10 jasonkadlec

jasonkadlec

    Advanced Member

  • Members

  • 32 posts
  • Country: Country Flag

Posted 05 August 2013 - 06:02 PM

Rob - The e-commerce is through a software called Topspin - it provides everything except the website to display the "buy" button. The Topspin buy buttons pull in a bunch of CSS, and load the payment gateway etc. from Topspin onto your site via a modal... 

 

 

Let's not get the thread hung up on it though, I was just using it as an example of a larger exploration of displaying the custom meta content via custom post types - not a tutorial on building an ecommerce solution. I totally love WooCommerce... but we're off topic.

 

So let's use another example from another client I have which posts each week a meditative thought, and an affirmation, each with a graphic every week.

 

I made a custom post type called "Weekly-Meditation" - and 2 custom meta fields -- 'Meditation' and 'Affirmation'

 

I have an page which shows a loop of the Weekly Meditation posts, listing each week's meditation and affirmation.

 

I also have a single page to display each one on its own - the single page displays the content from the custom field "Meditation" and the custom field "Affirmation."

 

It seems like with DMS - there are two approaches to rendering the content from these two custom fields which are associated with the custom post type.

 

Create a "child theme" then:

 

Option 1 - Create a section for the loop, and put all the code needed to display the mediation and affirmation loop. Then create a page template, then go to that page, edit it with DMS, and drag the section into where I want to see it on the page.

 

Then do the same for the single page view of each week.

 

Option 2 - Build a section for each component - so a section that displays the meditation, a section to display the meditation graphic, a section to display the affirmation, a section to display the affirmation graphic.

 

Now, I can create various pages to display that stuff ... 

 

My question with Option 2 - is -- in order to display the custom meta for the meditation graphic, for example - one can't just drop that anywhere... it needs to be within a loop that has queried the posts for my custom post type "Weekly-Meditation".

 

 

LOOOONNNGGGG story short.

 

There are tons of reasons to have custom post types and to make custom fields associated to those custom post types.

 

I (and I'm sure so many others) would love a tutorial from the PageLines developers giving some best practices on how to approach building sites using DMS + custom post types and custom fields. 

 

I was hoping this thread would provide some of that insight -- would you be open to requesting a developer to check out this thread, and hopefully be able to assist in what I'm really asking for - not a specific solution to a specific problem, but instead-

 

A general understanding of how to do an old thing ( make custom post types with custom fields) in a new way ( using DMS ). 

 

Thanks again for taking all this time, and sorry for not being more clear with the ask in the first place!



#11 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 07 August 2013 - 04:32 PM

I'm working on answering the rest of your posting, but in the meantime, have you seen this plugin? http://wordpress.org...rdpress-plugin/



#12 jasonkadlec

jasonkadlec

    Advanced Member

  • Members

  • 32 posts
  • Country: Country Flag

Posted 07 August 2013 - 04:42 PM

Rob - thanks for digging that up. Unfortunately, The Uprising Creative who built that plugin are not really supporting it -- things got pretty buggy with that plugin after WordPress 3.5 -- and anyway I have a different layout for my client than what that plugin does out of the box.  

 

But again - I don't want to get hung up on e-commerce or Topspin or any of that.  

 

Thanks for taking a look at answering the rest of the posting -- I hope others who use Custom Post Types and Custom Fields / Custom Meta and want to make the switch to DMS will appreciate your response, as will I. 



#13 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 07 August 2013 - 04:52 PM

@jasonkadlec,  Personally, not being a developer, I can't answer such technical things as our developers can. But you may have noticed we're still in the process of restoring things. So our developers are literally on their last thread of sanity, working 20 hours a day trying to get things back to normal.  I could ask them, but they'll just yell, rant and scream.

 

To be clear, custom fields are nothing new with WP, and once a custom field is added to a post, it's in the post.  We don't, as far as I know, need to do anything special for that post to display the info in the custom field.  That said, you would obviously want to deal with styling it, because it should just inherit the rest of the styling from the post and may need unique styling (like position, color, etc.).

 

There are many plugins that specialize in helping to make custom post types and display them as fields, but I suspect you've got that bit down pat.

 

Now, if you have a PHP snippet that calls the custom post type via a query, that's great.  You can use that PHP snippet in a button, like an a href link to make a button.  Go to http://demo.pagelines.me/tools. Scroll down to Buttons sometimes people need something to click and you'll see how you can make a button and use a link.

 

I will as our docs department to look into the custom post types, fields and meta issues and generate something ASAP.

 

Meanwhile, in trying desperately to help, have you seen this? http://wordpress.org/plugins/types/

 

It might help, but of course, I don't know where you're skills go. Apologies.



#14 jasonkadlec

jasonkadlec

    Advanced Member

  • Members

  • 32 posts
  • Country: Country Flag

Posted 07 August 2013 - 05:10 PM

Rob - 

 

Exactly - I LOVE the Types plugin. It is absolutely the best for making custom post types, and then for adding custom fields to those post types.

 

Understood that the developers are slammed -- if there is a team writing documentation / tutorials, then this is one for them.

 

It would be super nice if they did a little "if you're using the Types plugin" then to display the custom fields & custom post types then do this:

 

[ input from docs team goes here ]

 

It's pretty clear that making a child theme, and then adding your own "sections" files into that child theme is one way to get the job done.

 

Would be nice to hear from the docs team if that is, in fact the way PageLines envisions getting it done, and if not, then what way is the best practice for PageLines to display content from custom post types and custom themes.



#15 jakarn

jakarn

    Newbie

  • Members
  • Pip
  • 2 posts
  • Country: Country Flag

Posted 08 August 2013 - 01:09 AM

@jasonkadlec, we are using Types as well and we struggled for a while before coming across quite a simple solution.....

 

Types actually included shortcodes to show their fields, so you can actually do something like this in a DMS textbox: Resource id: [types field="resource_id"]

 

You specify the Types field without the wpcf prefix that it has in the post meta.

 

Hope this helps.



#16 jasonkadlec

jasonkadlec

    Advanced Member

  • Members

  • 32 posts
  • Country: Country Flag

Posted 08 August 2013 - 03:52 AM

@jakarn - that's the ticket right there! WOOT.



#17 bfrye26

bfrye26

    Super Member

  • Members

  • 110 posts
  • Country: Country Flag

Posted 14 August 2013 - 05:01 AM

@jasonkadlec did you sort it out so that meta boxes shows up properly in a DMS site? I would love to pick your brain on how you got everything working. Running into issues myself and want to be able to add that stuff in



#18 jasonkadlec

jasonkadlec

    Advanced Member

  • Members

  • 32 posts
  • Country: Country Flag

Posted 14 August 2013 - 09:31 PM

@bfrye26 - haven't jumped into just yet, but my next move was to use the Types plugin then use shortcodes as suggested by @jakarn

 

If you've already got the custom fields created... I thought I saw somewhere that you may be able to get Types to "take over" your already created custom posts... not sure if I dreamed that up with wishful thinking though.

 

If you don't have types, or can't get Types to take over your existing CPTs and Content so you can spit out the content with shortcodes, then I'm pretty sure you can create a child theme, and then create a section. Into that section put your loop - query posts and the whole bit. 

 

Then you should be able to drag that section into the DMS page template and I think it should work - the section you created would be in the "Miscellaneous" tab, next to the star.

 

If you're not sure how to make a child theme, or make a section - get the base theme here: http://pagelinesdevc.../base-products/

 

if you did that and it didn't work... do tell. 



#19 bfrye26

bfrye26

    Super Member

  • Members

  • 110 posts
  • Country: Country Flag

Posted 15 August 2013 - 01:32 PM

When I last tried Types it did not import the data from the custom field sadly. Also another issue I had with Types is it is painfully slow when compared to alternatives using the default fields aspect of Wordpress. It is rather easy to add the data from ACF only issue is making it display in the section rather then just the direct post and ensuing it all looks good. I would love to discuss it further if you would like







Also tagged with one or more of these keywords: CPT, Custom Post Types, Meta