How to Make SEO SearchTerms Tagging 2 Plugin Can Display the Actual Link to Search Terms Which Not Derived from WordPress Post or Page

The following modification will show you how to make the SEO SearchTerms Tagging 2 (STT2) plugin can display the actual link to the search terms which not derived from WordPress Post or Page. As we know, not all search terms that produced by this plugin has a link to the specific Post and Page content. When visitor came from the search engine to the site that uses this STT2 plugin, there are three possibilites that can be happened. The first possibility: visitor clicks on the link that point to the certain Post or Page in WordPress, so the search term has a link to the actual post/page and the value that stored in post_id field in stt2_meta table is greater than zero. The second possibility: visitor clicks on the link that point to the homepage of the site, even the search engine provides the link to the related post/page. This will cause the search term has a link to the homepage/front of the site (not to the actual related post/page), and the value in post_id field is zero. The third possibility: visitor clicks on the link that point to the certain custom content type, for example, you are using Pods CMS plugin. This will cause the value in post_id is always zero, no matter what. So this modification will give you solution in order to overcome the problem in the third possibility (in this case, the first possibility is normal, whereas the second one is also normal, but can be happened anytime as if this cause the search term does not have the link to the Post nor Page in WordPress).

  1. First of all, we have to alter the _stt2_meta table structure that used by the STT2 plugin. Add a new field to this table named content_url with the field type = text. The reason why we use text field type since we have to handle if the URI to related search term has the number of character greater than 255. Afterwards, don’t forget to edit the value of this new field with slash character ( / ), since we cannot define the default value when we are creating that new text field type.
  2. Open your /searchterms-tagging-2/searchterms-tagging2.php file, and find this code:

    $result = $wpdb->get_results( "SELECT `meta_value`,`meta_count`,`post_id` FROM `".$wpdb->prefix."stt2_meta` ORDER BY `last_modified` DESC LIMIT ".$count.";" );

    then replace with this following code:

    $result = $wpdb->get_results( "SELECT `meta_value`,`meta_count`,`post_id`,`content_url` FROM `".$wpdb->prefix."stt2_meta` ORDER BY `last_modified` DESC LIMIT ".$count.";" );
  3. Still in the same file above, find this code:

    $success = $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->prefix."stt2_meta ( `post_id`,`meta_value`,`meta_count` ) VALUES ( %s, %s, 1 )
    			ON DUPLICATE KEY UPDATE `meta_count` = `meta_count` + 1", $ID, $meta_value ) );

    then replace with this following code:

    $url = $_SERVER['REQUEST_URI'];
    $success = $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->prefix."stt2_meta ( `post_id`,`meta_value`,`meta_count`,`content_url` ) VALUES ( %s, %s, 1, '$url' )
    			ON DUPLICATE KEY UPDATE `meta_count` = `meta_count` + 1", $ID, $meta_value ) );
  4. Still in the same file above, find again this code:

    $permalink = get_permalink( $post->ID );

    then replace with this following code:

    $permalink = ( 0 == $term->post_id ) ? 'http://'.$_SERVER['SERVER_NAME'] . $term->content_url : get_permalink($term->post_id);
  5. Find again this code in that file above:

    $permalink = ( 0 == $term->post_id ) ? get_bloginfo('url') : get_permalink($term->post_id);

    then replace with this following code:

    $permalink = ( 0 == $term->post_id ) ? 'http://'.$_SERVER['SERVER_NAME'] . $term->content_url : get_permalink($term->post_id);
  6. Find again this code in the same file above:

    $result = $wpdb->get_results( "SELECT `meta_value` FROM `".$wpdb->prefix."stt2_meta` ORDER BY RAND() LIMIT ".$count.";" );

    then replace with this following code:

    $result = $wpdb->get_results( "SELECT `post_id`,`meta_value`,`content_url` FROM `".$wpdb->prefix."stt2_meta` ORDER BY RAND() LIMIT ".$count.";" );
  7. Open your /searchterms-tagging-2/widget.php file, and find this code:

    $permalink = ( 0 == $term->post_id ) ? get_bloginfo('url') : get_permalink($term->post_id);

    then replace with this following code:

    $permalink = ( 0 == $term->post_id ) ? 'http://'.$_SERVER['SERVER_NAME'] . $term->content_url : get_permalink($term->post_id);

The conclusion for all of modification above is if the post_id value in _stt2_meta table is 0, then save the URI of the search term that came from the search engine. So, when STT2 display the link to each search term, then it will show the link to the URI instead of to the homepage link that still happened until when this solution was found.

Share

1,026 viewsPrint This Post Print This Post

Comments

  1. Namit Gupta says:

    Any idea, how can we manually display the SearchTerms Tagging 2 Plugin’s Incoming Search Terms at any location? I mean to say using any manual code? I searched the wordpress.org page of Search Terms Tagging 2 plugin but didnt find anything there. Please let me know if you have any idea. Thanks.

  2. TreTans.com says:

    STT2 Gak dibolehin ma Host Server.. bikin lemot katanya… :(

  3. Mantab mas…
    Saya baca di forum tetangga, konon STT2 sudah tidak mumpuni lagi ya dengan logika algoritma panda yang baru????
    Terimakasih share nya…
    Salam kenal.. saya pernah membaca anda di sebuah aplikasi visual basic.. Salut…

Speak Your Mind

*


*