Forums

[Plugin: NextGEN Gallery] wp_ngg_tags and wp_ngg_pic2tags missing/moved after upgrade (26 posts)

  1. AengusM
    Member
    Posted 10 months ago #

    Hi all,

    Hope someone can point me in the right direction here searching hasn't located anything and bare with me as I'm not a db guru by any means

    Just upgraded NextGen to 1.02. Installed files Ok and was able to run the db upgrade successfully (based on wp-admin saying so).

    I had a search feature which looked at the wp_ngg_pic2tags and wp_nggtags tables (as well as the other tables) but both tables are missing following upgrade.

    I assume they have been integrated somewhere else as the tags are showing with I look at the pics in "Manage Gallery" and they also show under the tags link.

    I have a backup if I need to reload the tables.

    Can anyone advise?

    Cheers,

    Aengus

    P.S. this was my query (allow for slight change caused by posting)

    $nngquery = "
    SELECT pid,description,alttext
    FROM wp_ngg_pictures
    WHERE MATCH (description, filename, alttext) AGAINST ('*$keywords*' IN BOOLEAN MODE)
    AND exclude = '0'
    UNION
    SELECT pid,description,alttext
    FROM wp_ngg_pictures, wp_ngg_tags, wp_ngg_pic2tags
    WHERE pid = picid and tagid = id and
    MATCH (name) AGAINST ('*$keywords*' IN BOOLEAN MODE)
    AND exclude = '0'

  2. AengusM
    Member
    Posted 10 months ago #

    sorted...found them under wp_terms

  3. tommo77funk
    Member
    Posted 10 months ago #

    Hi AengusM,

    Glad, you are sorted, well done ! Dont suppose you could share how your query looks now ? My searching next-gen has not been the same since upgrading, and I had it working perfectly thanks to your code (and your girlfriends) from your other post. So I would be massively grateful to share what the new tags are, I dont know where wp_terms is ?

    Great wishes,

    tom

  4. AengusM
    Member
    Posted 10 months ago #

    Hi Tom,

    My search was returning absolutely no results and no error, as if there was no results, so stage one have made the following change within functions.php (root of theme)....

    hashed out the union...
    ##UNION
    ##SELECT pid,description,alttext
    ##FROM wp_ngg_pictures, wp_ngg_tags, wp_ngg_pic2tags
    ##WHERE pid = picid and tagid = id and
    ##MATCH (name) AGAINST ('*$keywords*' IN BOOLEAN MODE)
    ##AND exclude = '0'

    and in the following lines changed nggallery to nggGallery;
    '.nggGallery::get_image_url($pic[pid]).'
    and on next line;
    '.nggGallery::get_thumbnail_url($pic[pid]).'
    (note no change to ngg-Gallery);

    This first step has search returns for keywords in the Alt/title and description fields, I'll get to the tags in the next few days.

    I also tried re-implementing (is that a word?) the standard wp search pages assuming that with the tags integrated into the wp-tax that may return results but no joy...so I'll look at mapping the old ngg_tags and pics2tags.......unless someone else has a better suggestion?

    Aengus

  5. tommo77funk
    Member
    Posted 10 months ago #

    Hi AengusM,

    Thanks for reply, I am at the same stage as you, although search for title and alt are still a little wayward. As it was before actually, but your code for tags, solved that problem.

    Wish I could make a good suggestion to solve it, hopefully Alex might be along soon :) Until then I will also be working on it too. In the new nggfunctions.php from line 555, there is mention of tags, and I am hoping to find the new tags here. Couple found already are nggTags, gallerytag... so I will place these in the code and see what happens...

    Good luck and thanks !

    tom

    p.s. I think re-implementing is a good word

  6. tommo77funk
    Member
    Posted 10 months ago #

    There is also new tags.php in the lib folder, answer maybe here,

    line 314

    // first get all $term_ids with this tag
    $term_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_id FROM $wpdb->terms WHERE slug IN ($sluglist) ORDER BY term_id ASC "));
    $picids = get_objects_in_term($term_ids, 'ngg_tag');

    I think maybe...

    wp_ngg_tags = ngg_tag

    wp_ngg_pic2tags = terms

  7. tommo77funk
    Member
    Posted 10 months ago #

    dont work... sorry !

  8. AengusM
    Member
    Posted 10 months ago #

    I can see the new relationships, just busy and wouldn't get to trying for another 24 hours, involves wp_term_relationships table and object_id / term_taxonomy_id and term_id in wp_terms table.

    We'll get there!

    Aengus

  9. AengusM
    Member
    Posted 10 months ago #

    Here you go Tom, compliments of the girlfriend again ;-)

    testing not 100% completed...but looking good...

    UNION
    SELECT pid,description,alttext
    FROM wp_ngg_pictures, wp_terms, wp_term_relationships
    WHERE pid = object_id and term_id = term_taxonomy_id and
    MATCH (name) AGAINST ('*$keywords*' IN BOOLEAN MODE)
    AND exclude = '0'

    Aengus

  10. tommo77funk
    Member
    Posted 10 months ago #

    hi AengusM,

    HOO- nearly-RAY !!! Well done mate and please thank your v.clever girlfriend from me !!! I've been at meetings away from home all day, and got back an hour ago. I checked this post before even making my obligatory cuppa ;)

    Just wanna check my overall code with you guys cos although much improved its bringing up a few weird results, but that could be for any number of strange wordpress reasons, and if its perfect for you guy'z then I'll know it must be something else.

    So here you go

    ## Function to do searchs on gallery pics from NextGen Gallery plugin
    ##
    ## 2 vars : (1) $keywords (usually coming from the standard search query from wordpress)
    ## (2) $numberPicCol (number of pic by row, if null it takes 4 )
    function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
    global $wpdb;
    $count=1;
    if (!$numberPicRow) { $numberPicRow = "4"; }
    $nngquery = "
    SELECT pid,description,alttext
    FROM wp_ngg_pictures
    WHERE MATCH (description, filename, alttext) AGAINST ('*$keywords*' IN BOOLEAN MODE)
    AND exclude = '0'
    UNION
    SELECT pid,description,alttext
    FROM wp_ngg_pictures, wp_terms, wp_term_relationships
    WHERE pid = object_id and term_id = term_taxonomy_id and
    MATCH (name) AGAINST ('*$keywords*' IN BOOLEAN MODE)
    AND exclude = '0'
    ";
    $pictures = $wpdb->get_results($nngquery, ARRAY_A);
    if ($pictures) foreach($pictures as $pic) {
    $out .= '';
    $out .= '<img class="ngg-gallery" style="border: .1em solid #FFFFFF" src="'.nggGallery::get_thumbnail_url($pic[pid]).'" alt="'.stripslashes($pic[alttext]).'" title="'.stripslashes($pic[alttext]).'" />';
    $out .= "\n";
    if ($count == 0) {
    $out .= "";
    }
    ++$count;
    $count%=$numberPicRow;
    }
    return $out;
    };

    I will be testing and tweaking a little anyway. How is it working for you ?

    I hope it works great and i've just another problem somewhere else.

    Anyway thanks so much, I am mega grateful !!!

    Great wishes,

    tom

    p.s. Saw your website today and your underwater pictures are worthy of wildlife photographer of the year competition, have you ever entered ? They really are amazing !

  11. AengusM
    Member
    Posted 10 months ago #

    Here we go, lets hope this posts OK (full contents of my functions.php);

    <?php
    if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'name' => 'Sidebar Top',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));
    
    ## Function to do searchs on gallery pics from NextGen Gallery plugin
    ##
    ## 2 vars : 	(1) $keywords (usually coming from the standard search query from wordpress)
    ##		(2) $numberPicCol (number of pic by row, if null it takes 4 )
    function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
    	global $wpdb;
    	$count=1;
    	if (!$numberPicRow) { $numberPicRow = "4"; }
    
    	$nngquery = "
    SELECT pid,description,alttext
    FROM   wp_ngg_pictures
    WHERE  MATCH (description, filename, alttext) AGAINST ('*$keywords*' IN BOOLEAN MODE)
    AND exclude = '0'
    UNION
    SELECT pid,description,alttext
    FROM wp_ngg_pictures, wp_terms, wp_term_relationships
    WHERE pid = object_id and term_id = term_taxonomy_id and
    MATCH (name) AGAINST ('*$keywords*' IN BOOLEAN MODE)
    AND exclude = '0'
    				";
    	$pictures = $wpdb->get_results($nngquery, ARRAY_A);
    
    	if ($pictures) foreach($pictures as $pic) { 
    
    		$out .= '<a href="'.nggGallery::get_image_url($pic[pid]).'" title="'.stripslashes($pic[description]).'" class="thickbox" rel="gallery'.$pic[pid].'">';
    		$out .=  '<img class="ngg-gallery" style="border: .1em solid #FFFFFF" src="'.nggGallery::get_thumbnail_url($pic[pid]).'" alt="'.stripslashes($pic[alttext]).'" title="'.stripslashes($pic[alttext]).'" />';
    		$out .=  "</a>\n";
    				if ($count == 0) {
    				$out .= "";
    				}
    				++$count;
    				$count%=$numberPicRow;
    	}
    	return $out;
    };
    
    ?>
  12. tommo77funk
    Member
    Posted 10 months ago #

    hey AengusM,

    Thanks for that, its very generous of you to help and share your code, i appreciate it !

    Although it is working for me, I am getting some odd results.

    Try it yourself and see, here The search bar is in the header. Also I have image library page with tags here

    do a search for "lion" and you will get lion pics and hippo pics.

    do a search for "seal" and you will get seal pics and waterfall pics.

    gorilla brings up gorilla pics and birds !

    I could go on, but i'm sure you are getting the idea, there is something untoward, and I just cant put my finger on it. I have tried disabling all plug-ins, checking next-gen galleries, but after that I am flummoxed on what to try next. At least it is bringing relevant results, which is much better than nothing, so I am thankful for that.

    Do you happen to know how to check webpages for php errors ? Hopefully that will help, I will do a Google search now ;) I guess maybe its the same as validating a web page.

    Anyway many many thanks Aengus, if you are'nt experiencing problems, you should mark this post as resolved, sorry I've hijacked it...

    Cheers buddie, have a great day/night !

    tom

  13. tommo77funk
    Member
    Posted 10 months ago #

    WOOOOOOOO HOOOOOOOOOOOOOO !

    I think I fixed my problem, I took out "object_id and" from this line "WHERE pid = object_id and term_id = term_taxonomy_id and" and it seems to have got rid of the bogus images. I will keep testing but things are on the up :)

    tom

  14. tommo77funk
    Member
    Posted 10 months ago #

    still a bit ropey on the tags, but much improved :) in fact i'm not sure the tags are being searched at all, how are your tags Aengus ?

  15. AengusM
    Member
    Posted 10 months ago #

    Hi Tom,

    all Ok with me and I have spent a bit of time testing, however, I only search the gallery tags and not the blog, as you can see here I use a dedicated search page solely for the images.

    So my search.php would look very different to yours (and you should have extra components in your functions.php)...this my search.php;

    <?php
    get_header();
    ?>
    
    <div id="content">
    Search results;
    
       <?php if(is_search()) {
    	$search = $wp_query->get('s');
    	$keywords = preg_replace('/\+/',' ',$search);
    	if (function_exists ('ngg_get_search_pictures')) {  // function from functions.php
    		$nggpictures = ngg_get_search_pictures($keywords, '6'); // put the number of pictures by row you want, if you don't want "4"
    
    		if ($nggpictures) {
    			echo "<h2></h2>";
    			echo $nggpictures;
    		}
    	}
    }
    
    ?>
    Want to refine or do another Search?
    
    <?php include (TEMPLATEPATH . '/searchform.php'); ?>
    </div>
    <?php get_sidebar(); ?>
    <!-- The main column ends  -->
    <?php get_footer(); ?>

    As I understand it, NextGen is heading towards integrating the NextGen tags with the Wordpress tags so without looking too hard into it, I'm not surprised to hear of "Double" returns, whereas the code above is really for Pic Gallery search only.

    The whole idea of the UNION section is to search not just the tags but also the pic title and the alt/Description component and the object_id component is part of what links the components together.

    Hope above makes sense?

    Great Pics by the way...but I have to tell you, nothing beats the NYE fireworks down here in Sydney ;-)

    Cheers,

    Aengus

  16. tommo77funk
    Member
    Posted 10 months ago #

    hey Aengus,

    What you say makes a lot of sense, so I will now try to make the searchform in my image library just for images. Its a bit trickier than I thought it would be though ;(

    Anyway I cant thank you enough for all the help given on this post, and wish you the very best for the future. Talking of which I was wondering what you think of my idea here as I try to evolve my site into fully blown picture library.

    Hope your well, please pass on my gratitude to your partner 1 last time :)

    cheers,

    tom

    p.s. yeah, I know our fireworks are piddly, ha ha.

    p.p.s. Ever thought of doing some underwater 360 degree panorama's ? do a search on google and it has already been done but is in its infancy. Would love to do it myself, but I cant get water in my ears, so this is next best thing ;) If you ever need any advice on it, please do not hesitate to contact me. I owe you....

  17. wt4y
    Member
    Posted 10 months ago #

    Hello all,
    I love your web site AengusM and I would like to incorporate your search function in my web site. Just last week I ported over my site from S9Y (Serendipity) and I'm really loving Wordpress. I'm still trying to wrap my brain around the structure of Wordpress and need some help with "what code to put where", etc.

    Could you describe where each code snippet goes? I use the Amazing-Grace theme and it doesn't have a search.php or searchform.php. I can see where I would insert your ngg_get_search_pictures function in my functions.php, but what code is in searchform.php and what code goes on the actual Page. Is the exec-php plugin required to insert code on a Page?

    You can see my web site at http://wt4y.com/. I have about 900 images and would like to give my visitors the ability to search.

    Thanks for sharing.

    Gary

  18. wt4y
    Member
    Posted 10 months ago #

    OK I figured it out. From http://lorelle.wordpress.com/2006/02/11/understanding-and-fixing-wordpress-search/ I learned a bit about how the Wordpress search works. By adding my own search.php to my theme (which did not have one in the first place), Wordpress automatically used it instead of its built-in search function. Also, since I use a different prefix to my database tables, I had to change the calls to the database in the ngg_get_search_pictures function. I'm almost there now.

    Cheers!

  19. AengusM
    Member
    Posted 10 months ago #

    Glad you got sorted Gary and thanks for that great link.

    Aengus

  20. rdsherwood
    Member
    Posted 10 months ago #

    Hi Aengus & Tom:

    Thank you so much for posting all of this information. I am not a PHP programmer, but I've been able to take the code you've posted, and by trial and error have gotten an image search function to work on my site, for the most part. However I'm getting some odd results that have me stumped. I'm hoping you (or someone else) might be able to provide some insight:

    I have MANY pictures of elk on my site. The term elk is used in the image titles, descriptions and tags. Yet if I do a search on elk, I get no hits. If I search on bull (I use bull as a tag, as in "bull elk", I get hits. Same thing with sheep, goat, whale - I get hits on all of those. Yet not on elk - a keyword used more than any other keyword in my photos. Any ideas?

    My web site is http://www.sherwoodimagery.com. The search function does both a search on images, then a search on posts, and displays results from both. So if you do a search on elk you will get a hit from one of my posts - but not the picture search.

    Thanks again for sharing all this information, and thanks in advance for any insight you might be able to provide on my search problem.

    Regards,

    Ron

  21. tommo77funk
    Member
    Posted 10 months ago #

    Hi rdsherwood,

    Nice site :) erm what you describe is a problem I have with my own site and have not found the answer yet. The problem seems to be when you use the search for posts as well as images. Aengus's search is just for images and works as intended. It is mentioned in this thread that future updates to next-gen might hopefully intergrate next-gen tags with wordpress tags, and this would solve the problem. For now though I'm sorry I cant help other than to have one searchform for posts and another for images on a dedicated image search page. Which I seem to remember being a little tricky getting a searchform to use a different search.php template. If I find any other solutions, I'll let you know.

    Best wishes,

    tom

  22. rdsherwood
    Member
    Posted 10 months ago #

    Hi Tom:

    Thanks for the quick reply. Actually, I tried the search.php that Aengus posted above that only searches on images and not posts. It gave me the same results - it just wouldn't find some keywords, in my case "Elk". So I'm not sure this problem is identical to yours. Of course it could be that I made some other error in its implementation, as I said, I'm hacking my way through this. When I have some time, I'll go back and experiment with it again.

    It sounds like the Nextgen update to use Wordpress tags would be the ultimate solution. Hopefully that will happen soon. In the meantime, if you come up with any revelations, I'll be much appreciative if you share them here. Of course I will do the same.

    Regards,

    Ron

  23. AengusM
    Member
    Posted 10 months ago #

    Hi Ron,
    just searched on your site for Elk and got a couple of dozen shots back...is your issue fixed?
    Glad above was of some help at least!
    Cheers,
    Aengus

  24. rdsherwood
    Member
    Posted 10 months ago #

    Hi Aengus:

    When I do the search, I'm getting a return on posts that contain the word Elk, but nothing back from the Nextgen gallery search. Are you seeing gallery images when you search, or just the posts?

    Regards,

    Ron

  25. AengusM
    Member
    Posted 10 months ago #

    Ah I see, I'm getting a post back with pics not just pics.
    What I've done is just to return pics, I've removed the post component from search.php (see above and compare with yours).
    Not sure what you need to do but suspect answer is the search.php syntax.

    I did my original adjustments based on Psykotik's post;
    http://www.ikiru.ch/blog/2008/how-to-add-a-search-function-for-nextgen-gallery-wordpress-plugin.

    A quick interim fix for you is maybe to setup a "Search Pics" "Search blog" using a second search.php?

    Aengus

  26. nancyb7
    Member
    Posted 2 months ago #

    I have posted my search code for NextGen Gallery 1.3.5 in a more recent thread, along with an explanation of why the search for "Elk" has problems. I could not have found the correct code without this thread and the links it contains, the older thread http://wordpress.org:80/support/topic/206946, and Psykotik's post.

Reply

You must log in to post.

About this Topic