-1

I have created some custom post types with the CustomPress plugin. It has generated some PHP to use which outputs the value of that custom post type. See example below:

<div class="post-wrap"><?php echo do_shortcode('[ct id="_ct_text_58d8fb56bfbac" property="value"]'); ?></div>

What I need to do now is write some PHP that basically does the following -

If custom post id="_ct_text_58d8fb56bfbac" has some content show the above div containing with the in it, but if the custom post id has no content do not display the div containing it at all, or output some other HTML content within the wrapping div.

Note: The custom post ID changes depending on the custom post type I am working with. This is sitting in a custom-single-post.php WordPress template. I have approx 20 custom post types listed like the above.

Thanks Kindly

EDIT:

I have this working so far - but I can't figure out how to output the actual content of the custom post value.

<?php if ( '' !== get_post_meta( get_the_ID(), '_ct_text_58d17e89dbd35', true ) ) { echo '<div class="meta-found">' . 'VALUE OUTPUT HERE' . '</div>'; } else { echo '<div class="nothing-found">' . 'Nothing Found' . '</div>'; } ?>

closed as off-topic by cybmeta, cjbj, bosco, Dave Romsey, Howdy_McGee Apr 3 '17 at 15:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • I don't understand your question very well. Do you want to check if the custom post type has content, if it does output the content or if not output a default message in HTML? – Chess Byte Mar 29 '17 at 13:48
  • Where is the code you posted located? What is the relevance of that shortcode? Where are do you intend to place the PHP you are asking about? Without knowing what "abc" and "xyz" are, it's difficult for anyone to suggest how you might accomplish them. Please review the "How to Ask" page in our help center, and then edit your question to clarify what you are attempting to accomplish, what you've tried, and what problem you've encountered. – bosco Mar 29 '17 at 20:11
  • Hi Both, I have expanded my question. Please let me know if this helps at all? Thank you kindly – Richard Bland Mar 30 '17 at 15:06
  • The plugin is generating a shortcode which outputs the content for that id. If you want to add conditionals if something is empty do this or that you will need to write a custom loop for that query and check if the field is empty etc. doubtful that anyone will provide code here, they normally don't unless you make a very good effort to show your attempt with a loop, args for that post type, and so forth. There are many examples out there and the codex has a lot too. – Christina Mar 30 '17 at 15:24
  • @Christina - Thank you, please see my attempt below - so far it is working, but I can't get it to output the custom post's value. – Richard Bland Mar 31 '17 at 13:18
0

I figured it out in the end from a combination of trial and error from a few different sources. Here is what I came up with in the end:

<?php $key_1_value = get_post_meta( get_the_ID(), '_ct_datepicker_58d1755e1a654', true ); if ( ! empty( $key_1_value ) ) { echo '<div class="mtt date-added">' . '<span>' . 'Date Added:' . '</span>' . $key_1_value . '</div>'; } ?>

This is just one custom post ID, I have several each requiring their own div containers and css etc. but the has done the job. I can now output the custom post value into a div container of my creation, and if it is empty it just won't show at all.

Thank you to everyone who did steer me down the right route.

Not the answer you're looking for? Browse other questions tagged or ask your own question.