Support » Plugin: Custom Field Template » [Plugin: Custom Field Template] Unable to insert NextGen Gallery into textarea field

  • Hi,

    While I can select one of the galleries just fine from NextGen, it won’t insert the shortcode into the Custom Fields Template textarea. How do I get this to work properly?

    Also, is there a way where this will work with regular fields, so the user can click on NextGen, select the desired gallery, and pow, it inserts the shortcode into a basic text field, thus not a textarea field?

    Thanks for an awesome plugin.

Viewing 15 replies - 1 through 15 (of 25 total)
  • Okay, I just learned that the shortcode is being inserted, however, it’s inserting into the main text area up top, thus not in the custom fields. Any idea on how to fix this?

    Thanks.

    Hi there,

    I have done something similar with NextGen and the CFT.

    I used a select drop down that grabs the NextGen Gallery data. This code is from a previous project I worked on, I’ll share it with you:

    Template:

    [gallery]
    hideKey = true
    label = Select Gallery for this page. <br /> <a href=/wp-admin/admin.php?page=nggallery-manage-gallery>Click here</a> to modify the order of your gallery.
    type = select
    code = 0'

    Code Block 0

    global $wpdb;
    	$values = array();
    	$attachments = $wpdb->get_results('SELECT gid,title,path FROM wp_ngg_gallery');
    	foreach ($attachments as $attachment) {
    	$str = '[' . $attachment->gid . ']----->'.$attachment->title .'<-----!!' .$attachment->path . '!!';
    	$values[] = $str;
    	 }

    That will make a drop down containing the gallery id [id] the name of the gallery and the !!path!! to the gallery folder. I put them in delimeters so as to be able to extract them in the template. I think I needed both !!path!! and [id] to get it working. You can adjust the $str to how you want it displayed to your editor.

    You may just want to have the shortcode [nggallery id=x] being used in the field. That edit will be easy to make:

    $str = '[ngggallery id=' . $attachment->gid . ']';

    In you template you will just have to apply filters on that custom field that you’ve made so it outputs the gallery.

    In your template:

    <?php
    $unprocessedfield = get_post_meta($post->ID, 'nameofyourcustomfield',true);
    $processedfield = apply_filters('the_content', $unprocessedfield );
    echo $processedfield;
    ?>

    That should get you moving in the right direction.

    Wow, thanks for all your help.

    I implemented the code you pasted, unaltered (not sure if I was supposed to change any values) and I’m getting part of it to work. The drop menu appears, but none of the gallery options. I tried placing the your code in the Magic Fields admin template part. Am I supposed to alter it and/or place it elsewhere?

    I really appreciate your efforts and time here. Seriously. That’s way cool of you.

    Peace.

    Hi,

    If the gallery drop down is empty, perhaps the code block code is wrong.
    First of all I can spot an error with the first part of the template code:

    [gallery]
    hideKey = true
    label = Select Gallery for this page. <br /> <a href=/wp-admin/admin.php?page=nggallery-manage-gallery>Click here</a> to modify the order of your gallery.
    type = select
    code = 0

    The other code block needs to go into the PHP Code Experimental Option section (not in the same template block). This code works for an older installation of NextGen 1.5

    global $wpdb;
    	$values = array();
    	$attachments = $wpdb->get_results('SELECT gid,title,path FROM wp_ngg_gallery');
    	foreach ($attachments as $attachment) {
    	$str = '[ngggallery id=' . $attachment->gid . ']';
     $values[] = $str;
    }

    Does that work?

    Hmmm, I did as suggested, but no dice.

    I copied the first chunk of code and placed it in the Custom Fields Template per your suggestion, then copied the other code block and pasted it into the PHP Code Experimental Option section. Unfortunately, the dropdown menu still comes up empty. I’m using the latest NextGen Gallery, as well as WP.

    Thanks again for your help.

    Ok,

    The code does work, I’ve tested it.
    How are you storing your images? In NextGen galleries I hope because this outputs complete galleries.

    Yep, in NextGen galleries. You know what though, I’ve been playing with the Magic Fields plugin and it’s really doing everything I want. I may just abort this CFT mission.

    That said, I really don’t want to waste your time. Thanks for your consistent efforts. Seriously. Much appreciated.

    One last thing…do you think running php4 has anything to do with the issue? I’m pretty sure that’s what my host is running.

    No it will work with php4, but I’d move host php 4 is really old!

    Yeah I have heard good things with Magic Fields but I’ve stuck with CFT.

    A shame that we couldn’t sort this issue out.

    Hey, I’m still down to sort it out if you are. I’d like to have a good competitive custom fields’ program in the event Magic Fields go awry or something. Nice to have backup.

    So yeah, got any other ideas as to what may be the problem? I’ll keep testing.

    Thanks.

    Try this code in a php template.

    <?php
    	global $wpdb;
    	$values = array();
    	$attachments = $wpdb->get_results('SELECT * FROM wp_ngg_gallery');
    
    	echo '<pre>';
    	echo 'query results: ' . print_r($attachments);
    	$wpdb->print_error();
    	echo '</pre>';	
    
    	foreach ($attachments as $attachment) {
    		$str = '[ngggallery id=' . $attachment->gid . ']';
     	$values[] = $str;
    	}
    
    	echo '<pre>';
    	echo '$values: ' . print_r($values);
    	echo '</pre>';
    ?>

    This is the error I get:

    Parse error: syntax error, unexpected '<' in /home/xxxxxx/public_html/wp-content/plugins/custom-field-template/custom-field-template.php(1691) : eval()'d code on line 1

    I only get this error when I couple your latest code above (placed in the PHP CODE area) this code in the Template content area:

    [gallery]
    hideKey = true
    label = Select Gallery for this page. <br /> <a href=/wp-admin/admin.php?page=nggallery-manage-gallery>Click here</a> to modify the order of your gallery.
    type = select
    code = 0

    As of now, those are the only two sections of code I’m using. Well, code that I received from you. Not sure if I’m supposed to combine them with some of your other code above or anything.

    Thanks for the continued help.

    Hi again,

    Sorry should’ve been more clear. The last code submitted is a test. You should put it on a page (page.php) and then load that page in your browser.

    The output will help to see where things are not working.

    Thanks.

    JHouse

    (@jhouse)

    This crossed my mind yesterday…since I’m already totally locked on Magic Fields and thus don’t see myself using CFT anymore (although it’s a cool plugin), and since you already have it working on your host, I guess I don’t see a reason to get this working on my set up anymore given that I highly doubt I’ll use it now or in the future.

    That said, I really don’t want to waste your time any further. I’m well aware that I stated I would stick around ’till we sort it out, but is it productive time spent for either of us? You know what I mean? If, however, you want to be able to test your code out for whatever reason and get this to work, I’ll stay around and test it out.

    Anyways, I totally respect and appreciate your time. Much much appreciated. You were very consistent with your support.

    Take care man.

    Hi proximity2008,

    no idea if this will get to you but i am trying to do something similar. I want to populate a select box (drop down) using CFT’s “experimental php code” with a array of bundles as the valuelabel, and an array of sku’s of the bundles as the value. Im still learning when it comes to php so any help is super appreciated.

    Basically i have a db table called bn_bundles, and in that table is a column called bundle, and a column called sku. I just dont know how to plug that into something that CFT could use.

    The idea is someone can select from a drop down which bundle they want to display.
    They are presented with the bundle names to choose from, but the value i want to pass to the page is the sku.

    Thank you for taking time to read this.

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘[Plugin: Custom Field Template] Unable to insert NextGen Gallery into textarea field’ is closed to new replies.