• 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 10 replies - 16 through 25 (of 25 total)
  • actually i think i got something working. Might have answered my own question, this appears to be working.

    global $wpdb;
    	$values = array();
            $valueLabel = array();
    	$attachments = $wpdb->get_results('select * from bn_bundles order by bundle asc');
    	foreach ($attachments as $attachment) {
    	$str = '[' . $attachment->bundle . ']';
            $str2 = '[' . $attachment->sku . ']';
    	$values[] = $str ;
            $valueLabel[] = $str2 ;
     }

    Sorry to rain on people parade but I believe I have found a much more simple solution.

    Go to the tinymce.js file and replace line 68 window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, tagtext);

    with

    tinyMCEPopup.editor.execCommand('mceInsertContent', false, tagtext);

    @proximity2008

    Sorry to bump an old thread but was hoping you could help me. I have used the code you supplied and it seemed to be working. When I check the page on the site though, all I see is the value that appears in the dropdown menu instead of the actual gallery. Could you possibly help me to get the actual gallery to display on the page?

    I am working on a project now where this would be a huge help. I never even thought of this as an option but now that I see it is possible, I would love to get it to work.

    (Hopefully you see this! ??

    Hey Adam,

    It’s good that you have the number being output, you are almost done.

    What has to happen now is that WordPress needs to recognise that value as standing for a gallery id. NextGen uses a shortcode to do this, so you’ll need to run the_content filter on that ID.

    Now I haven’t used NextGen for ages but as per above the shortcode is: [ngggallery id="X"] where X is the ID of the NextGen Gallery.

    In your templte file somewhere:

    <?php
    $cft_id = get_post_meta( $post->ID, 'gallery', true );
    echo apply_filters( "the_content" , "[ngggallery id='{$cft_id}']" );
    ?>

    That should output the gallery I think.

    The code I am using in the PHP Code section of CFT is:

    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;
    }

    The code in my page template is what you just pasted above:

    <?php
    $cft_id = get_post_meta( $post->ID, 'gallery', true );
    echo apply_filters( "the_content" , "[ngggallery id='{$cft_id}']" );
    ?>

    When I do that the result I get on my page is:
    [ngggallery id='[ngggallery id=1]‘]

    Easy fix:

    <?php
    $cft_id = get_post_meta( $post->ID, 'gallery', true );
    echo apply_filters( "the_content" , "{$cft_id}" );
    ?>

    So close… ??

    It is showing the correct code now:
    [ngggallery id=1]

    Though WordPress is wrapping that in paragraph tags, so instead of showing the gallery it is showing the code. Can I eliminate the paragraph tags?

    Thank you so much for your quick help on this.

    I’ve spotted it now. There is a typo back in your CFT Php code section.

    See the tripple g in ngggallery.

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

    Edit: Wait I just went back and changed the php code template to the previous version we used and it works now. Thank you very much for your help on solving this.

    The code that works, for anybody that wants to do this themselves is:

    This goes in your page template:

    <?php
    $cft_id = get_post_meta( $post->ID, 'gallery', true );
    echo apply_filters( "the_content" , "[nggallery id='{$cft_id}']" );
    ?>

    This goes in the PHP Code Section of Custom Field Template:

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

    This goes in the Custom Field Template Options:

    [gallery]
    hideKey = true
    label = Select Gallery for this page.
    type = select
    code = 0

    Thanks again for your help!

    FYI when I implemented the code above it displayed an extra parenthesis and a bracket underneath the photos like such: ‘]

    To get rid of it I just modified the php code in the template to look like this:

    <?php
    $cft_id = get_post_meta( $post->ID, 'gallery', true );
    echo apply_filters( "the_content" , "[nggallery id={$cft_id}" );
    ?>

    I simply removed the closing bracket and parenthesis at the very end of the code. Not sure if this is compliant but it works.

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