Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Display custom data from a database table on CPT single page WordPress

  • SOLVED

I own a custom plugin that makes its own database tables and imports data automatically from an external database of real estate listing data.

The plugin has shortcodes but apparently they're not registered with wordpress because do_shortcode doesn't work on them (just displays the shortcode text, just like do_shortcode('[hello]'); would do -- output [hello] in plain text on the page). However, the shortcodes work inside the content area (the WYSIWYG/HTML editor).
So, I imagine it's not super simple to just MAKE them become "real" shortcodes. If that's possible, let's do that.

An alternative method is to just say select 'field_address' from 'table_myplugin' where 'field_idnumber' = get_post_meta($post->ID, 'customfield_idnumber', true).
So, how do I do this?

Here's a template for the front-end display:
-CPT post title
-custom field for video url
-[gallery] shortcode to display images
-<strong>some (not all) of the custom query results</strong> (e.g. #bedrooms, #bathrooms, etc.)
-shortcode for Contact Me about this property
-<strong>some more (different than above) custom query results</strong> (e.g. written description, address, directions, etc.)

Here's the layout of the database tables created by this plugin:
2 tables: [[LINK href="http://screencast.com/t/VgEBisbUZ9Mn"]]http://screencast.com/t/VgEBisbUZ9Mn[[/LINK]]
per listing data table: [[LINK href="http://screencast.com/t/vsmOpevO7rD"]]http://screencast.com/t/vsmOpevO7rD[[/LINK]] & [[LINK href="http://screencast.com/t/JApEJ6x1"]]http://screencast.com/t/JApEJ6x1[[/LINK]]
fields table: [[LINK href="http://screencast.com/t/Qtf4y5cix"]]http://screencast.com/t/Qtf4y5cix[[/LINK]] & [[LINK href="http://screencast.com/t/vCaRxEVt"]]http://screencast.com/t/vCaRxEVt[[/LINK]]

Please provide me with a way to make a shortcode turn into a "real" shortcode and/or provide me with the custom query(ies) needed to display the information. I think I'm looking for a single query that pulls all the data for this specific listing and then I can use some code or shortcut to display the selected items at will. For example:
Beds: {queryresults="beds"}
Baths: {queryresults="baths"}

or

Beds: queryresults[beds]->$post
Baths: queryresults[baths]->$post

I don't know exactly, but whatever is fine as long as it's WP standards / best practices and works.
Ideally, if there field is blank or NULL, I'd like to display
Beds: (italic)Information not available(/italic)
instead of just displaying
Beds:

Or even better (if beds is null/blank and baths is not and garage is not):
Baths: 3
Garage: 4

instead of
Beds:
Baths: 3
Garage: 4


Thank you.

Answers (2)

2012-10-23

Dbranes answers:

Hi, here is one idea to try:

<?php echo apply_filters( 'the_content', '[hello]');?>


Clifford P comments:

sure enough, that worked. I tried that for other things and it wasn't what I needed. Guess it is now. So, for my $15, could you give a laymen's terms explanation of EXACTLY how that filter works? ;-) thanks.


Dbranes comments:

that's great ;-)

Since the shortcode look-a-like [hello] is only working from the editor, it is a possibility that your plugin is using

add_filter("the_content","some_function");


to deliver the results via <em>str_replace</em> or <em>preg_match</em>, but not

add_shortcode("hello","some_function");


So if you need to apply a Wordpress filter to some $text, you can use this.

<?php echo apply_filters( $filter, $text ); ?>


where $filter can fx. be <em>the_content</em>, <em>the_title</em>, <em>sanitize_title </em>, ...

Here are useful codex pages:

http://codex.wordpress.org/Function_Reference/apply_filters

http://codex.wordpress.org/Plugin_API/Filter_Reference

Hope this helps.



Clifford P comments:

Beautiful. I will pass on to the plugin creator.

All that makes sense, just that the_content filter did some crazy stuff when I was trying to use it before and caused me to misunderstand what was going on. All's good now. Thank you.

2012-10-23

Luis Abarca answers:

Maybe the shortcodes are no registered, that's why it returns the shortcode, try to register them.

And try again with


<?php echo do_shortcode('[hello]') ?>


Clifford P comments:

you must not have read the question in full...