presenting the results of the form

Dear all,
I created the custom forms and it worked in terms of storing this information and editing/reviewing the filled info, but since I press publish, nothing yet happened!

Can smb guide me how to present the results of the filled out forms on a single page separately one by one (including the uploaded files that went with this form) sorted by the descending date.
Thanks in advance/Best,
Michal

  • James Morris

    Hello Micha?,

    I hope you are well today. Thank you for your question.

    Since CustomPress is essentially just for creating custom post types, taxonomies and custom fields, the display of such data should be treated the same as with any other method inside WordPress. If you could provide access to your site via the Support Staff Login and give us the page names of where you're using CustomPress, we'd be happy to take a deeper look into this for you.

    You can learn how to grant WPMU DEV Support Access at the following link:

    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    Please reply back here once you've enabled access so I will be notified.

    Best regards,

    James Morris

  • James Morris

    Hello Michal,

    I see your data is indeed being published and the corresponding pages are being created. I gather what you're wanting to do is display all posts of this custom post type on a single page. Is that correct?

    While it's not really within the scope of the support forums to provide custom code for such situations, I'll be happy to give you some direction on what you need to do to accomplish this.

    What you will want to do is create a custom page template with your own custom loop to display all posts of that post type.

    The following code is your building block for doing something like this:

    <?php $loop = new WP_Query( array( 'post_type' => 'yourposttypehere', 'posts_per_page' => -1 ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    The stuff you want to loop goes in here
    <?php endwhile; wp_reset_query(); ?>

    There are many other great things you can do with custom loops. Here's a great article that breaks some of them down step-by-step: https://wp-agency.co.uk/update-wordpress-loop-custom-post-type/

    You would need to create a file titled page-procedury.php, upload it to your theme folder and create a new page and select this new template as the template for the page. You can learn more about custom page templates at the following article. https://premium.wpmudev.org/blog/creating-custom-page-templates-in-wordpress/

    Now, keep in mind, the exact code you will need to use in your page template can vary greatly depending on which theme you are planning on using. So, no single example can be given that will work in all situations. However, the above resources and the following links should give you the information you need to create your custom page template with custom loop.

    https://codex.wordpress.org/Post_Type_Templates
    https://codex.wordpress.org/Post_Types

    Using the above resources, you should have no issue creating a custom page template that will loop through all of your procedury post types and post them on one page. Please keep in mind, though, your global setting of whether to show the entire post or just the excerpt will be inherited.

    Let us know if you have any further questions. We'll be happy to help!

    Best regards,

    James Morris

  • Michał

    Thank you for your clues - I'll work on that. I have two follow up questions:
    1) Ideally I'd like to list all of the names of procedures and their respective authors (so only two of the custom fields) and make that name clickable with a link to the full description of such detailed description - can you guide me to do exaclty this?
    2) I'd like the uploaded files to be visible (downloadable) to all of the guests - can you guide me how to achieve this state?

    Best regards,
    Michal

  • James Morris

    Hello Micha?,

    I hope you are well today.

    The sample code I'm using here is based off a simple custom post type I've created and the native custom fields. However, with some minor modifications to match your custom post type and custom field keys, something like this should work quite well.

    * I copied the page.php file of my theme and renamed it page-list-custom-posts.php
    * I then created the page List Custom Posts. Since WordPress looks for page templates that match my page slug, the template I created is automatically used.
    * Inside page-list-custom-posts.php file I've replaced the standard WordPress loop with my own custom version as follows:

    <?php
    		$args = array( 'post_type' => 'custom', 'posts_per_page' => -1 );
    		$loop = new WP_Query( $args );
    		echo "<ul>";
    		while ( $loop->have_posts() ) : $loop->the_post();
    			$my_custom_author = get_post_meta($post->ID, "my_custom_author", true);
                echo "<li>" . $my_custom_author . "</li>";
    			$my_custom_title = get_post_meta($post->ID, "my_custom_title", true);
                echo "<li><a href=\"" .get_the_permalink(). "\">" . $my_custom_title . "</a></li>";
    		endwhile;
    		echo "</ul>";
    	?>

    You will want to change the following values:

    'post_type' => 'custom' to the custom post type defined in CustomPress
    $post->ID, "my_custom_author" to the meta key defined in CustomPress for the Author custom field
    $post->ID, "my_custom_title" to the meta key defined in CustomPress for the Title custom field

    This will output a simple unordered list of authors and titles as seen in the screenshot. https://monosnap.com/file/ixaNU0SAFxGBNysPaCh6Txh7z7syLU

    Of course, this all can be customized further to suit your needs, but the above should serve as a basic starter example.

    Now, to force download of your files, you can do so by adding something like the following to your .htaccess file, assuming you're wanting to force download of PDF files, for example.

    <FilesMatch "\.(?i:pdf)$">
      ForceType application/octet-stream
      Header set Content-Disposition attachment
    </FilesMatch>

    This will take any link you place on your site that has a .pdf extension and force it to be downloaded.

    I hope this clarifies a bit more.

    Best regards,

    James Morris

  • Michał

    Dear James,

    We are building a repository for questionairres that people upload themeselves - example: http://repozytorium.badania.net/kwestionariusze/skala-do-pomiaru-poczucia-samotnosci-de-jong-gierveld/

    We have tried everything, but we were unable to turn the icon of the upload media to appear as a clickable URL

    Suggested by you .htaccess solution did not work. Could you change the code within the custom plugin to accomodate that.

    The code that delivers this site http://repozytorium.badania.net/kwestionariusze/skala-do-pomiaru-poczucia-samotnosci-de-jong-gierveld/
    is as follows
    <?php
    // Start the loop.
    while ( have_posts() ) : the_post();

    /*
    * Include the post format-specific template for the content. If you want to
    * use this in a child theme, then include a file called called content-___.php
    * (where ___ is the post format) and that will be used instead.
    */
    get_template_part( 'content-kwestionariusze', get_post_format() );
    echo "<table id=\"hor-minimalist-a\">";
    echo "<thead><h1><tr><th scope=\"col\" id=\"kolumna\">" . $my_custom_title . "</h1></th>";
    echo "</tr>";
    echo "</thead>";
    echo "<tfoot><tr><td>";
    echo "<h3>Pobranie narz?dzia mo?liwe tylko dla zarejestrowanych u?ytkowników repozytorium</h3></td></tr></tfoot>";
    echo "<tbody><tr><td>";
    echo do_shortcode('[custom_fields_block wrap="table"] ct_Nazwa_narz_text_8c35, ct_Autor_auto_text_90ea, ct_Autor_auto_text_73b6, ct_Materiay_r_textarea_81c7, ct_Mierzony_k_textarea_2280, ct_Opis_narzd_textarea_8b9d, ct_Zastosowan_textarea_5723, ct_Informacje_textarea_ae7f, ct_Zacz_arkus_upload_674f [/custom_fields_block]');
    echo "</td></tr>";
    echo "</tbody></table>";

    // End the loop.
    endwhile;
    ?>

    How to turn that icon into a clickable URL? Htaccess method failed (on many different tries).

    Best regards/Pozdrawiam,
    Micha?

  • Predrag Dubajic

    Hi Micha,

    Could you try adding below code to your theme functions.php or crete mu-plugin for it:

    function create_download_link() { ?>
    <script type="text/javascript">
    	jQuery( document ).ready(function() {
    	    jQuery( 'img[src="http://repozytorium.badania.net/wp-includes/images/media/document.png"]' ).wrap( '<a href="DOWNLOAD_URL"></a>' );
    	});
    </script>
    <?php }
    add_action( 'wp_footer', 'create_download_link' );

    Replace DOWNLOAD_URL with download URL and that should do the trick.

    Best regards,
    Predrag

  • Adam Czajczyk

    Hey Michal!

    I can see on the site that the code that my colleague Predrag suggested has been used "as is". That's why it doesn't work. In that line:

    jQuery( 'img[src="http://repozytorium.badania.net/wp-includes/images/media/document.png"]' ).wrap( '<a href="DOWNLOAD_URL"></a>' );

    the DOWNLOAD_URL string has to be replaced with an actual link to the file.

    The questions now is how to do this "dynamically" so it would lead to the file that's assigned to this page. The solution could be to output the custom field value in that code instead of "DOWNLOAD_URL" string. For example:

    - let's say the field holding a link to the file has an ID of "ct_Zacz_arkus_upload_674f"
    - it's value can be displayed with following shortcode:

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

    - Predrag's code could then look like this:

    <?php
    function create_download_link() { ?>
    <script type="text/javascript">
    	jQuery( document ).ready(function() {
    	    jQuery( 'img[src="http://repozytorium.badania.net/wp-includes/images/media/document.png"]' ).wrap( '<a href="<?php echo do_shortcode('[ct id="ct_Zacz_arkus_upload_674f" property="value"]');?>"></a>' );
    	});
    </script>
    <?php }
    add_action( 'wp_footer', 'create_download_link' );

    Give it a try please and let me know if it worked for you.

    Best regards,
    Adam

  • Michał

    Well, I knew the link I pasted was not good, but I soon discovered that the icon was not turning into a clickable link so the code did not work.

    Now I've pasted the suggested:

    <script type="text/javascript">
    	jQuery( document ).ready(function() {
    	    jQuery( 'img[src="http://repozytorium.badania.net/wp-includes/images/media/document.png"]' ).wrap( '<a href="<?php echo do_shortcode('[ct id="ct_Zacz_arkus_upload_674f" property="value"]');?>"></a>' );
    	});
    
    </script>?>
    <?php }
    add_action( 'wp_footer', 'create_download_link' );

    But the result is the same - the icon is unclickable.

    Any ideas?

    Best,

    M.

  • Adam Czajczyk

    Hello Michal!

    I visited the site again and it seems that the code is actually turning the icon to a link but the HTML code "breaks". Let's then move backwards a bit to make a "clean start"

    The icon in "Arkusz narzedzia" row on the page is supposed to link to a PDF file, so when you click on it a PDF document should open, is that right?

    A direct URL (full URL) of that file is stored within a custom field and that field ID is ct_Zacz_arkus_upload_674f, is that correct too? Or is it a different field?

    I'm sure we'll get it to work and we're on a right track, I just want to make sure that we're using proper data

    Best regards,
    Adam

  • Adam Czajczyk

    Hi Michal!

    Thank you for your replay.

    I did some more testing and it seems it's a "glitch" in CustomPress. The plugin handles values of "upload-type" custom fields as images only. Furthermore, it doesn't store a file URL as the field value but only an attachment ID.

    I have already reported it to developers as an "upload" field suggest that any type of file could be uploaded there and that should be handled accordingly to the file type.

    I also got a solution for you. Please note though: it will only work well if there's just a single file uploaded per field. To use it on site make following changes:

    1. Remove codes that Predrag and I suggested previously to make icon clickable
    2. Add this code as an mu plugin

    <?php
    function wpmu_ct_upload_field_downloadable($atts) {
    global $post;
    
        extract(shortcode_atts(array(
            'id' => '',
        ), $atts));
    
    	$meta_url = wp_get_attachment_url( get_post_meta( $post->ID, $id, true ) );
    	return '<a href="'.$meta_url.'">'.$meta_url.'</a>';
    }
    add_shortcode( 'ct_upload_field_downloadable', 'wpmu_ct_upload_field_downloadable' );

    To do this, simply create an empty file with .php extension (e.g. "ct-downloadable-field.php"), paste the code inside (using "clean text" editor such as e.g. Notepad++, Sublime or similar) and upload it to the "/wp-content/mu-plugins" folder of your WP install; if there's no "mu-plugins" folder inside "wp-content", create it.

    The code above creates an additional shortcode so you will need to make one more change.

    3. Inside your custom loop replace this part

    echo "<tbody><tr><td>";
    echo do_shortcode('[custom_fields_block wrap="table"] ct_Nazwa_narz_text_8c35, ct_Autor_auto_text_90ea, ct_Autor_auto_text_73b6, ct_Materiay_r_textarea_81c7, ct_Mierzony_k_textarea_2280, ct_Opis_narzd_textarea_8b9d, ct_Zastosowan_textarea_5723, ct_Informacje_textarea_ae7f, ct_Zacz_arkus_upload_674f [/custom_fields_block]');
    echo "</td></tr>";

    with this one

    echo "<tbody><tr><td>";
    echo do_shortcode('[custom_fields_block wrap="table"] ct_Nazwa_narz_text_8c35, ct_Autor_auto_text_90ea, ct_Autor_auto_text_73b6, ct_Materiay_r_textarea_81c7, ct_Mierzony_k_textarea_2280, ct_Opis_narzd_textarea_8b9d, ct_Zastosowan_textarea_5723, ct_Informacje_textarea_ae7f [/custom_fields_block]');
    echo do_shortcode('[ct_upload_field_downloadable id="ct_Zacz_arkus_upload_674f"]');
    echo "</td></tr>";

    As a result your page should display a clickable link to the file instead of not-working icon. In case you still wanted to display a clickable icon instead of a clickable URL, you would need to make one more change and in my code from point #2 above replace this line

    return '<a href="'.$meta_url.'">'.$meta_url.'</a>';

    with this one

    return '<a href="'.$meta_url.'"><img src="http://repozytorium.badania.net/wp-includes/images/media/document.png"></a>';

    I hope that helps

    Best regards,
    Adam

  • Adam Czajczyk

    Hi Michal!

    Hm... I tested this solution on my end but I must admit that apart from that particular "upload-type" custom field I didn't use more "complex" structure. I'm not sure why it's not working for you but I expect it to be something rather simple that I'm just missing.

    It'd be a bit difficult to proceed though while I can only see the site "from outside" so do you think it would be possible to either access your site directly? If I was able to check custom fields configuration, template files and the database (which I did on my test setup in order to come up with suggested solution) I think I would be able to find that "missing point" and make it work

    If it's an acceptable option, please send in:

    Subject: "Attn: Adam Czajczyk"

    - Mark to my attention, the subject line should contain only: ATTN: Adam Czajczyk
    - Do not include anything else in the subject line, doing so may delay our response due to how email filtering works.
    - Link back to this thread
    - login URL and admin account login credentials (may be a temporary admin account) data
    - Include FTP log-in details (hostname, username & password)
    - Include hosting control panel access details (login address, username & password) - cPanel's usually the control panel used for this, but your provider may use something else; I'll need this for accessing your site's database, preferably via phpMyAdmin
    - Include any relevant URLs for your site

    Please use our contact form here https://premium.wpmudev.org/contact/#i-have-a-different-question

    In case it wasn't possible, let me know please and I'll try to proceed other way.

    Best regards,
    Adam