Calling data from custompress custom fields

Hi, I have gingerly started using custompress on a site. I have created a post type called 'maps', with a taxonomy called 'references' & some custom fields which are a variety of text boxes, drop downs & checkboxes. I'd like to know how to call the field into posts and pages, particularly in the following:
Call all the 'maps' posts type into a page.
In each 'map' post show the text included in the 'references' taxonomy.
In each 'map' post show the text from the text box custom field.
In each 'map' post show the selected text option from the dropdown custom field.
In each 'map' post show a ? symbol when a checkbox is ticked.
I have looked on your support forums & not find any instructions, please can you help me out?

  • Kasia Swiderska

    Hello Barnaby,

    Call all the 'maps' posts type into a page.

    Do you mean that you want list of all the maps custom post types placed on one page? This require
    a) writing custom page template where custom post types will be listed with use of separate WP query https://codex.wordpress.org/Class_Reference/WP_Query (tool for generating query code https://generatewp.com/wp_query/ )
    b) use plugin like that https://pl.wordpress.org/plugins/custom-content-shortcode/screenshots/

    In each 'map' post show the text included in the 'references' taxonomy.
    In each 'map' post show the text from the text box custom field.
    In each 'map' post show the selected text option from the dropdown custom field.

    Each custom filed can be shown in post type by placing right shortcode related to that filed into post type content. You will find shortcodes for your custom post type in CustomPress custom fields list when you hover on custom field and click Embed Code

    so in your map post you would place shortcode like that:

    [ct id="_ct_selectbox_4cf582bd61fa4" property="value"]

    In each 'map' post show a ? symbol when a checkbox is ticked.

    This will be tricky because you will need to incorporate this one in to single-map.php template because this one requires checking the value of the field

    $meta = get_post_meta( get_the_ID(), '_ct_selectbox_4cf582bd61fa4', TRUE );
    
    if ( $meta == 'yes' ) {
    echo '?';
    }

    simplest way to create template for your custom post is to copy content of single.php template (you will find it in your theme directory) to single-map.php and then add required code into it.

    let me know if you have more questions.

    kind regards,
    Kasia

  • Barnaby

    Hi Kasia,
    Thanks for your reply. I think I must have put it badly. I would like all the map type posts to appear in my front page & I have ticked the checklist in custompress settings that I thought would make this happen.
    I have also created the single-map.php by checking the 'create template file' in the custompress settings but when I click on a map type post, it shows a blank page. I can get it to show something by including the shortcode in the map type post editor but I need it to appear without using the shortcode. So I need to know how to embed the php code you mentioned into the single-map.php.

    I'm quite a newbie to custom posts and fields etc so I apologise if this is really basic!
    Please could you tell me the loop to bring the map post types into the front page & the function I need to put into the single-map php please?

  • Nithin

    Hi Barnaby,

    Hope you are doing good today. :slight_smile:

    Did you mean the template single-map.php shows a blank page? Could you please try creating a new template, with a default theme, and check whether you are still getting the same result. I did test this in my system, and it seems to work.

    By default custom fields are not visible, you'll have to embed the code in your custom template, as showing in the screenshot:

    Please could you tell me the loop to bring the map post types into the front page

    Could you please check whether you have disabled the default checkbox, in order to get the post types displayed in your frontpage.

    If you still have issues, could you please enable support access so that we could give a look. Please let us know how that goes, have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • Barnaby

    Hi Nithin,
    Thanks for your reply. I have managed to create a 'single-maps.php' that shows some content including some of the custom fields. (Thanks to Kasia!)
    As I want the custom post types to be structured differently from the standard posts, I have created a page called 'content-custompress.php' to structure the 'maps' custom types & whatever other custom post types I end up creating.
    So my remaining questions are:
    1,) How do I call the custom post types into the front page? I have already unchecked the 'default' option in the CustomPress settings as you mentioned.
    2,) I see in the 'Post Types' tab where I have created the 'Maps' post type that I can have a singular name, which I have called 'Map'. How do I call that singular name into my 'content-custompress.php' file?
    3,) I appreciate this isn't so much to do with the plugin but I thought you might be kind enough to help me. In the 'content-custompress.php' I'm trying to include a link that looks like this:
    <?php
    if ( is_single() ) :
    the_title( '<h4 class="entry-title">', '</h4>' );
    endif;

    if ( 'post' === get_post_type() ) : ?>

    <?php
    endif; ?>
    I would like to add this code:
    a href="#" onclick="toggle_visibility('map-01');">...</a
    either side of the H4 in the title, however the onclick event seems to be preventing the post from rendering, how should I code that to make it work?

    Thanks again for your help Nithin, I have given you support access, the website is being developed here: http://thedesign.social/tbc/

  • Barnaby

    Hi,
    I have managed to get the posts into my front page by adding this to the content-page.php template:
    <div id="maps">
    <?php $loop = new WP_Query( array( 'post_type' => 'maps' ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); get_template_part( 'template-parts/content-custompress', get_post_format() ); ?>
    <?php endwhile; wp_reset_query(); ?>
    </div>
    So that leaves me with questions 2 & 3:
    2,) I see in the 'Post Types' tab where I have created the 'Maps' post type that I can have a singular name, which I have called 'Map'. How do I call that singular name into my 'content-custompress.php' file?
    3,) I appreciate this isn't so much to do with the plugin but I thought you might be kind enough to help me. In the 'content-custompress.php' I'm trying to include a link that looks like this:
    <?php
    if ( is_single() ) :
    the_title( '<h4 class="entry-title">', '</h4>' );
    endif;

    if ( 'post' === get_post_type() ) : ?>

    <?php
    endif; ?>
    I would like to add this code:
    a href="#" onclick="toggle_visibility('map-01');">...</a
    either side of the H4 in the title, however the onclick event seems to be preventing the post from rendering, how should I code that to make it work?
    Thanks for your help

  • Barnaby

    Hi again,
    I have sorted question 3 out, I included it into 'content-custompress.php'.
    So that leaves me with question 2:

    2,) I see in the 'Post Types' tab where I have created the 'Maps' post type that I can have a singular name, which I have called 'Map'. How do I call that singular name into my 'content-custompress.php' file?

    But I also have an extra question based on the advice that Kasia gave earlier in the post about using an if function:
    4,) Is there a way to get an if function to work if two statements are true? Kasha earlier posted this:
    $meta = get_post_meta( get_the_ID(), '_ct_selectbox_4cf582bd61fa4', TRUE );

    if ( $meta == 'yes' ) {
    echo '?';
    }
    Which worked like a charm! But I would like the if test be something like:
    $meta = get_post_meta( get_the_ID(), '_ct_selectbox_57a8e9dbb08b8', TRUE );
    $meta = get_post_meta( get_the_ID(), '_ct_selectbox_57a8ea3e1497f', TRUE ); (probably bad coding!)
    if ($meta == yes & yes) { (definitely bad coding!)
    echo '?';
    }
    How do I get this to work?
    Again, thanks for your help!

  • Ash

    Hello Barnaby

    I see in the 'Post Types' tab where I have created the 'Maps' post type that I can have a singular name, which I have called 'Map'. How do I call that singular name into my 'content-custompress.php' file?

    Sorry, I don't think I am following you, what do you mean call singular name? This file is dedicated only for Map, right? So you can use your own custom code. Would you please rephrase?

    4,) Is there a way to get an if function to work if two statements are true? Kasha earlier posted this:
    $meta = get_post_meta( get_the_ID(), '_ct_selectbox_4cf582bd61fa4', TRUE );

    if ( $meta == 'yes' ) {
    echo '?';
    }
    Which worked like a charm! But I would like the if test be something like:
    $meta = get_post_meta( get_the_ID(), '_ct_selectbox_57a8e9dbb08b8', TRUE );
    $meta = get_post_meta( get_the_ID(), '_ct_selectbox_57a8ea3e1497f', TRUE ); (probably bad coding!)
    if ($meta == yes & yes) { (definitely bad coding!)
    echo '?';
    }
    How do I get this to work?

    Try the following:

    $meta1 = get_post_meta( get_the_ID(), '_ct_selectbox_57a8e9dbb08b8', TRUE );
    $meta2 = get_post_meta( get_the_ID(), '_ct_selectbox_57a8ea3e1497f', TRUE );
    
    if( $meta1 == 'yes' && $meta2 == 'yes' ) {
    echo '';
    }

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • Barnaby

    Hi Ash,
    Sorry, I thought I was putting it badly!
    I have created a custom post type called 'maps'. In the settings for this post type there is a label called 'Singular Name' which I have called 'map' How do I get 'map' to appear in 'my content-custompress.php' file? I've included an image of the 'Maps' post type settings page.

    Your suggestion for the if function with two statements worked like a dream, thanks so much for that!
    Just one further thing, that if function that Kasia posted worked for dropdown custom post fields but I can't get it to work if the custom field is a checkbox, I need something like this:

    $meta = get_post_meta( get_the_ID(), '_ct_checkbox_57a8eb447ca6c', TRUE );

    if ( $meta == 'if checkbox is ticked' ) {
    echo '?';
    }

    Where am I going wrong with this?

    Thanks again Ash!

  • Barnaby

    Hi Ash,
    I found a way to include the Singular Name label, just included this:
    <?php $post_type = get_post_type_object( get_post_type($post) );
    echo $post_type->labels->singular_name ; ?>

    So the final thing is how to get the checkbox to work:

    $meta = get_post_meta( get_the_ID(), '_ct_checkbox_57a8eb447ca6c', TRUE );
    if ( $meta == 'if checkbox is ticked' ) {
    echo '?';
    }

    Thanks again!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.