• Resolved volpv

    (@volpv)


    Hi Everett,

    I am using your plugin as a solution for basic projects functionality.

    I have create a custom post type called “my_projects” which will contain details about the individual projects.
    Now I am trying to display the list of all the individual projects in a page (something like All Projects Directory). For which I have created another custom post type “List of Projects” and have made “my_projects” as a repeatable custom field attached to “List of Projects”. While I can display the list , but I am not able to display some associated custom fields of “my_project” in the All Project Directory. I scanned the entire forum and used all possible versions of get_post function and other ideas as mentioned, without any success. Could you please advice?

    Also is it possible to link specific custom fields for e.g. Can I link Project Owner so that it appears as a link to individual member profile?

    Appreciate your help.

    Many Thanks

    https://www.ads-software.com/extend/plugins/custom-content-type-manager/

Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Contributor fireproofsocks

    (@fireproofsocks)

    It sounds like maybe you’re structuring your data inefficiently, and that leads to frustration. You’ve got 2 post-types here: projects, and a project-container of some sort, yes? So the big question here would be “can one project belong to more than one project-container?”

    If the answer is no, then maybe you should just use custom hierarchies and select the project-container to be the parent of each project. If the answer is yes, then consider using taxonomies to group the projects (i.e. scrap the “projects-container” post-type and use only the “projects” post type, then use a taxonomy to group them.) The important thing to me is whether or not your container has additional attributes that merit them having their own post-type and all the baggage that goes with that. If it’s merely a grouping device, then a taxonomy is a much better way to go. Or you could even define a dropdown/multi-select field for your projects and allow them to choose which container they belong to (that’s essentially exactly what tags/categories do).

    Beyond that, I’d need to see exactly what you’re doing. When you use a relation field, the only thing that gets stored is the ID of the other post. That’s an important tenet of data normalization: once you have the ID, you can get all other data points by looking up the data represented by that ID. In the manager, you can customize the manager HTML (see https://code.google.com/p/wordpress-custom-content-type-manager/wiki/CustomizingManagerHTML) so that when you select a related post, you can see more of its data (e.g. instead of just the title, maybe you want to see one of the values stored in its custom fields). E.g. if the related post has a custom field named “years_of_service”, then your .tpl files in the manager can use a [+years_of_service+] placeholder to display that data.

    There isn’t a “User” custom field, no, but this has been requested informally (a feature request would be helpful for that wink wink). The low-brow solution would be to store the id of the user in a text field, then use WP’s functions to look up the user info associated with that user id.

    Hope that helps.

    Thread Starter volpv

    (@volpv)

    Thank you very much for the steer. I was thinking of using the Project container only to list the individual projects , one as All Projects Directory and the other as All completed Projects Directory. I think your suggestion to get rid of Project Container Post Type and using Taxonomy should be the approach.
    All I am trying to do is to display the Projects in the same way as Groups Directory or Forum Directory currently gets displayed in the WP+BP.

    Can I send you the jpeg files of what I am trying to achieve in your email id?

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Better use Skitch or some other free image capture service so it stays in the forum.

    Thread Starter volpv

    (@volpv)

    Hi this is the code I am using , am not sure how to display the other custom fields associated with “my_project”
    here is the code I am using to display the Project titles https://pastebin.com/0K1fwt8Y

    Appreciate your help

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Use the “get_post” output filter instead. Whereas “to_link” grabs only the other post’s title and guid (in order to make a link tag), the get_post filter gets EVERYTHING, including custom fields: https://code.google.com/p/wordpress-custom-content-type-manager/wiki/get_post_OutputFilter (specifically example #2 there).

    If you used taxonomies, you’d have to dance around a bit more to make WordPress get that data, but the principle is the same: you’d be looping over the array of post_id’s and fetching info about them.

    Thread Starter volpv

    (@volpv)

    Many thanks for the steer. I am able to get the list now. But how do I make the title a click able link that will link to the individual projects?

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    You need to build standard HTML anchor tags. Just remember that the post’s guid is its URL. E.g.

    <?php
    $posts_array = get_custom_field('my_relation:to_array', 'get_post');
    foreach ($posts_array as $p) {
       printf('<a href="%">%s</a>: %s', $p['guid'], $p['post_title'], $p['my_custom_field']);
    }
    ?>

    Alternatively, use WP’s get_permalink() function to convert the post ID to a link.

    Thread Starter volpv

    (@volpv)

    Many thanks ?? ??

    Thread Starter volpv

    (@volpv)

    Hi Again,

    I am trying to print an image thumbnail as well along with the post title (I have defined prj_image as a custom field for the my project custom post) and am using the code here https://pastebin.com/X3H9Qs36

    But the image does not get displayed.
    Look forward to your advice.

    Many Thanks once again ??

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    First off, you have a bug in your HTML and PHP:

    <img src="<?php print $p[prj_image]; ?>"

    is missing the closing part of the image tag and the PHP array there needs to have quotes around the key (prj_image). So it should read:

    <img src="<?php print $p['prj_image']; ?>" />

    BUT, remember that the CCTM doesn’t store the image source! It stores post IDs. If you looked at your HTML source, you’d probably see something like this:

    <img src="123" />

    Right? That’s not what you want, but It’s soooooo important to use post IDs because they’re infinitely more powerful. I can’t stress this enough: this is database 101 stuff: you store a foreign key to the other post, then you look up the data you require. Wash, rinse, repeat.

    So if your ‘prj_image’ field is a CCTM image field, it will only contain the post ID of the image that it references. So you need to look up the other data via another function or output filter, .e.g

    <img src="<?php print CCMT::filter($p['prj_image'], 'to_image_src'); ?>" />

    Make sense? You could use built-in WordPress functions there too to get the same result as the CCTM::filter() function — they’ll do the same thing: look up the image’s info based on its ID. You always have to lookup the IDs and get the data from them that you want. So many parts of WordPress and other plugins get painted into corners because they use the image source instead of the post ID: it may be easier in the short run to do that, but it definitely will crumble under any serious usage in the long run.

    Thread Starter volpv

    (@volpv)

    Many thanks for explaining this in details.

    I tried using the above code but now nothing gets displayed. I also went and unchecked the thumbnail option in the global settings but nothing changed.

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    I had a typo– I wrote CCMT instead of CCTM:

    <img src="<?php print CCTM::filter($p['prj_image'], 'to_image_src'); ?>" />

    But that brings up another CRITICAL point: you will waste hours, days, weeks, even months of your life while you develop if you don’t turn on PHP errors. Literally. You are flushing your time down the toilet if you don’t enable PHP errors. At a minimum, add the following to your wp-config.php file:
    define('WP_DEBUG', true);

    If you had that enabled, you would have seen an error with that typo. I describe this stuff in detail in my book: https://www.amazon.com/WordPress-3-Plugin-Development-Essentials/dp/184951352X — the point is you MUST get your development environment set up correctly if you want to be a developer and achieve professional results.

    Beyond that, if you are getting the image ID, then it’s easy to turn that number into something useful. If you’re not getting the image ID, then you have to figure out why. What kind of field is ‘prj_image’? Is it a custom field you created with the CCTM? Or is it something else? And is it pointing to a valid image? Experience will teach you more than I can.

    Thread Starter volpv

    (@volpv)

    Many Thanks ??

    a newbie, I am and very much appreciate your steer. I have set up the Debug mode to true now and will dig further into how to set up the development environment correctly. Also many thanks for sending me the link to your book. I will definitely buy it ??
    The image is getting displayed now. But not as a thumbnail as I want it to be. ‘prj_image’ is an image type custom field created with the CCTM.

    well said…nothing can beat experience ?? the greatest teacher of all!

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Good job! You got the image!

    Getting a thumbnail is trickier — the “easy” solution is to just make the dimensions of your image smaller (e.g. width=”50″ instead of the width=”100″), but that’s sorta cheating. That’s what WP does in its media browser, I discovered ??

    The “better” solution is to use one of WP’s functions, e.g. https://codex.www.ads-software.com/Function_Reference/wp_get_attachment_image

    Instead of passing the ID to thru a CCTM filter, you’d pass the ID to that function and hopefully get back the smaller version of the image. However, I’ve found many caveats and I’ve been disappointed with WP’s image manipulation functions unfortunately ??

    There is a feature request to be able to resize images: https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=269

    I started doing some of that in 0.9.5, but I discovered that it was problematic: PHP would fail trying to crunch large images (white-screen of death), so you really need the ImageMagick extension installed, but not every server has it, unfortunately.

    Thread Starter volpv

    (@volpv)

    Thank you very much for the steer Everett. I will try it out. and update you.
    Now trying to link the Project Owner with the BP Member profile and Group to the corresponding BP Group. Phew!

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘[Plugin: Custom Content Type Manager] Ho wo display List of Custom Posts’ is closed to new replies.