Follow up question, re: earlier post about wanting to create checkboxes to add content to posts

Sorry... I started a thread earlier (https://premium.wpmudev.org/forums/topic/im-wondering-whether-you-have-any-plugins-that-can-help-me) but wasn't sure how to add a comment...

Re: CustomPress, I'm wanting to use the checkboxes to add content to posts. I've had a play around with CustomPress (just now) and managed to create some of the checkboxes I'm wanting, but am not sure yet how to add the content from the checked boxes as additional text at the bottom of the post (ie, the checkbox content is not currently published). Also wondering if it's possible to italicise the content that is inserted via CustomPress (so that it users can tell with a quick scan that it is quoted material and not something that individual users have created).

Looking forward to looking into BuddyPress as well... I use Gravity Forms at the moment but, honestly, it's so clunky that it was what caused me to start looking for alternatives to the plugins that I'm currently using (hence the sign up with you guys).

Great to hear that your Subscriptions plugin does what I need it to!

Thanks heaps for your help so far!

  • Tyler Postle

    Hey Toni,

    Thanks for getting back to me :slight_smile:

    To reply to one of your support tickets you will have to visit our actual site. You can see your past tickets here once logged in: https://premium.wpmudev.org/forums/profile/toni9

    We'll keep all further support in this thread if that works for you!

    We will have to place the field into the post template. Do you mind granting support access so I can see how you have the field setup so far?

    You can grant support access via admin dashboard - WPMU DEV > Support > Support Access > Grant Access.

    Look forward to hearing back!

    Cheers,
    Tyler

    PS. If you have any questions regarding the BuddyPress fields then you can open a new thread on that - it will keep the topics more organized if we're going deeper into them.

  • Tyler Postle

    Hey Toni,

    Thanks for doing that :slight_smile:

    I just went in and tested this out, hope you don't mind that I created a post draft. It should be deleted now.

    Place this code onto one of your post pages and make your selections then preview it:

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

    It should be showing your selected values. Then you want them to show up in italics right? Once we know it's showing what you want then we can place it in your post template file so you don't need to use the shortcode in each post :slight_smile:

    Look forward to hearing back Toni!

    Cheers,
    Tyler

  • Toni

    Okay, cool... that's working. As well as italics, is it possible to make it so that each checkbox item is on a new line?

    Also, I'm getting super fussy now so will cope if this isn't possible but I'm wondering if there's a way to make it so that each CustomPress Field on the Add a New Post page is able to drop down if selected (ie. automatically be hidden but drop down if the user requires it). I'm going to have at least five CustomPress Fields (potentially more if users request additional access to the curriculum document they reference), and I'm wanting to somehow tidy up the Add New Post screen so that they don't have heaps and heaps of options that mightn't be needed for their particular post.

    Thanks so much for your help, Tyler... there's no way I could have figured all of this out on my own!

  • Tyler Postle

    Hey Toni,

    Thanks for getting back to me :slight_smile:

    Okay, cool... that's working. As well as italics, is it possible to make it so that each checkbox item is on a new line?

    You can actually add the italics right into the value field for each checkbox content.

    Just wrap the value in

    <em>content</em>

    I notice you already made 1 underlined and bolded it :slight_smile:

    Knowing this we can now add line breaks to the end of each one as well:

    <em>content</em><br />

    That will make each one show up on it's own line.

    You will notice that I already added it for your first 3 options.

    Also, I'm getting super fussy now so will cope if this isn't possible but I'm wondering if there's a way to make it so that each CustomPress Field on the Add a New Post page is able to drop down if selected (ie. automatically be hidden but drop down if the user requires it).

    Hmm. You might have me on this one :p I will see if I can get this to work and if not I can ask another staffer here if they know how it can be done.

    Let's get the custom field into your post template first shall we.

    I will need access to your WordPress files to place in the code.

    Do you mind providing your FTP access?

    You can send it through our private contact form: https://premium.wpmudev.org/contact/

    Send in:

    Subject: "Attn: Tyler Postle"
    -FTP credentials (host/username/password)
    -link back to this thread for reference
    -any other relevant urls

    Select "I have a different question" for your topic - this and the subject line ensure that it gets assigned to me :slight_smile:

    https://premium.wpmudev.org/contact/

    Look forward to hearing back!

    Cheers,
    Tyler

  • Tyler Postle

    Hey Toni,

    Thanks for getting back to me and providing the screenshot too :slight_smile:

    I'm using a child theme and haven't created a post.php file yet

    When you do make it you can just paste this in where you want to display the custom field values:

    <?php echo do_shortcode('[ct id="_ct_checkbox_5430d2f43fd11" property="value"]'); ?>

    If you need help with that just let us know :slight_smile:

    As for the comma, we may have to custom code that as I think changing that separator may change it for other lists with CustomPress. Can you try putting the
    at the beginning of the option? Then it will be a comma separated list but the comma will stay on the same line - wondering if perhaps that might work for you, if not just let us know.

    Hope you're enjoying your Sunday Toni!

    Cheers,
    Tyler

  • Toni

    Hi Tyler,

    Following up on your offer to help with this: suddenly realised that there is no post.php and am not too sure if I should be adding this code to single.php or index.php - or maybe something else entirely.

    I would also really like to remove the comma entirely. While it will work on some lines, it's not going to work on all of them. Rather than relying on my clients to remove the commas themselves, I have a feeling I'll be dodging future maintenance requests by taking the comma out before clients have to work with it.

    Thanks again for all of your help so far.

    - Toni

  • Tyler Postle

    Hey Toni,

    Good to hear back from you!

    Yes, you would want to add it into the single.php file or to be more specific and make sure it didn't show up in other post types, you could make a copy of single.php and re-name it single-post.php then add it in there :slight_smile:

    Once we have it showing on the post then we can take a closer look at removing the commas.

    Look forward to hearing back!

    Cheers,
    Tyler

  • Toni

    Hi Tyler,

    I decided to make some changes to my website while I'm not working with clients, including adding multiple entry types and custom fields via CustomPress. I also created a single-post.php file, though have been struggling to figure out where to place the custom field values. I'm hoping you might be able to take a look at the file and give me a bit of a heads up? I've attached a screenshot of where I've added the code, but can give you access to the website as well if that's easier.

    Hope you've had a good xmas and managed to get some decent time off!

    - Toni

  • aristath

    Hello there @Toni, I hope you're well today!

    Checkboxes are boolean controls, meaning they can be true or false. So there's actually nothing to be echoed there because they have no actual content!

    What you could do however is replace your do_shortcode() functions with something like this:

    if ( get_post_meta( get_the_ID(), 'FIELD_KEY_HERE', true ) ) {
      echo 'This is active';
    } else {
      echo 'This is inactive';
    }

    Of course changing the FIELD_KEY_HERE with your own field keys.

    Let me know if that works for you!

    Cheers,
    Ari.

  • Toni

    Hi Ari,

    I don't really understand any of what you're saying. If there's nothing to be echoed, why does adding the shortcode to my post insert the custom fields into it? (See pic.) Surely that would mean that I can just add the shortcode php insert to my single-post.php file and then the job would be done. I just don't know where to add it.

    I have another question related to CustomPress - this time custom post types. I read here that I can add custom post types to my home page. I'm wondering how I'd alter the code to put the post types into a different page (my blog page, currently called Portfolio).

    Thanks,

    Toni

  • Michelle Shull

    Hey there, Toni!

    For your second question, there's a plugin you can use to make inserting the custom post types on your custom blog page a lot easier than creating a new function: https://wordpress.org/plugins/display-posts-shortcode/

    For your first question, do you mind walking it back with me a little so I understand how we got to this point? You've created a new custom field (for the checkboxes) but inserting the shortcode is only displaying the text, not the checkboxes or multi-select boxes themselves, right?

    Can you do a quick theme test for me, just to make sure we're not doing everything right already, and your theme is holding us up. Try switching to a different default theme and test this test page to see if the checkboxes appear. I'm not terribly hopeful this is the cause (it looks like you're using twenty fifteen) but let's rule it out just to be sure.

    Thanks, Toni!

  • Toni

    Hi Michelle,

    I'm wanting to embed the custom fields in my code - am not looking to display the checkboxes, simply the text related to the checked boxes (as shown in the two pictures previously submitted in this topic). Inserting the shortcode at the end of each post does the trick, but my site is a client-access site and I need everything to be as simple as possible for my clients: hence the desire to embed the code rather than rely on clients to add shortcode to each of their posts.

    I need to know where in single-page.php (as suggested by Tyler, above) to place the embed code as my efforts so far have proven fruitless (ie. not resulting in automatically adding the custom fields to posts).

    I'm fairly new to WordPress and have even less experience with php, but am keen to learn as much as I can (mostly so I don't have to keep annoying you guys with what are undoubtedly reasonably basic requests). I'm reading through a lot of the articles on the WPMU DEV blog and have implemented a number of suggestions, which has been helpful in reducing the number of plugins my site is using as well as helping me better understand how my site works. This has had the added benefit of not creating any unanticipated clashes between plugins, and I am keen to avoid adding non-WPMU DEV plugins where possible.

    - Toni

  • Tyler Postle

    Hey Toni,

    Hope you had a good Christmas as well :slight_smile:

    Your screenshot looks good, that should place them above the comments, but you just need to add an "echo" as the front of each line, so it would look like this:

    echo do_shortcode('[ct id="_ct_checkbox_5430d2f43fd11" property="value"]');

    That way they will be echo'd/displayed on the page.

    I still do a bit of trial and error when it comes to placing code inside templates to be honest :p paste code in, refresh page to check if it's where I want it, if not - cut and paste somewhere else haha.

    Let us know if you need any further assistance here Toni. More than happy to help!

    All the best,
    Tyler

  • Toni

    Hey Ari,

    I thought of that not long after my last post and created a content-post.php file to test it out (I removed the custom post formats and am just trying to add this to regular posts now). I copied the whole file and called it content-post.php, added it to my child theme and... nothing. The posts are publishing as though I hadn't added any code (ie. sans the custom fields), which makes me think I haven't done something quite right.

    I'm wondering if it might have anything to do with this:

    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.

    Is "post" a post format? I couldn't figure out what else to call the content-____.php file.

    - Toni

  • Toni

    Awesome, thanks Ari. Can confirm that the custom fields are now publishing in the right place on posts.

    Now that that's been taken care of, I'm wondering if we'd be able to start working through removing the commas that automatically get added to some of the lines (ie. selected check boxes) when they're added to a post.

    I'm also wondering how I'd go about styling the text that's added via the custom fields. From what I can tell, it's now being added as part of main post so doesn't have any separately styleable code, though I'm hoping I might have just missed something.

    Much thanks for all of your help so far: my site is looking and operating heaps better since both installing the WPMU DEV plugins and working with you all to sort through the challenges I've been having.

  • Tyler Postle

    Hey Toni,

    Hope you're doing well today!

    Do you want the comma's removed from just the end of the list? Keep the rest?

    As for styling the text. Since you're placing tags around the text in the value field, you could just place a class around them as well. Like this:

    <div class="custom-text">text goes here</div>

    Then you can target the .custom-text class. You can always change the class for the values you want to style differently as well :slight_smile:

    How does that sound?

    Look forward to hearing back!

    All the best,
    Tyler

  • Toni

    Alas, adding a class didn't work. It added in space before the commas (which I imagine would be fixed once commas get taken out) but none of my styles were applied.

    I added the following to my child theme's css:

    .mtopoutcome {
    		font-size: 14px;
    		font-size: 1.4rem;
    	}
    
    	.mtopcomp {
    		font-size: 12px;
    		font-size: 1.2rem;
    	}
    
    	.mtop {
    		font-size: 11px;
    		font-size: 1.1rem;
    	}

    and included three classes to the group of custom fields (mtop; mtopcomp; and mtopoutcome), though only applied one class to each field.

    I've been having trouble changing font size on larger screens and am wondering if I've got something else making it impossible for me. That said, the additional classes didn't make a shred of difference to font sizes even on smaller screens.

    (Nb. I added a class to Outcome 1 to test it out, but not to the rest of my custom fields... hence the differences between the different Outcomes.)

  • Tyler Postle

    Hey Toni,

    Thanks for your replies :slight_smile:

    So, you can remove the comma by editing the content-types.php file which is located via:

    /wp-content/plugins/custompress/core/content-types.php

    Around line 925 you will see this:

    switch ($custom_field['field_type']){
    
    		case 'checkbox':
    
    		case 'multiselectbox': {
    
    			if( $values = (array)get_post_meta( $post->ID, $id, true ) ) {
    
    				$result = implode( ', ', $values );
    
    			}

    Remove the "," from implode(', ', $values); so it now looks like:

    $result = implode( ' ', $values );

    That should remove the commas from between your fields :slight_smile:

    As for the styling, where did you place that CSS? Try using this plugin here: https://wordpress.org/plugins/simple-custom-css/

    That plugin was designed so it's stylesheet should be one of the last to load, if not the last to load, which means if there is overlapping styles between all the stylesheets it should take that one as priority.

    Hope this helps Toni! Let us know if you still need any further assistance.

    Cheers,
    Tyler

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.