• Hello, Help me understand why my product/taxonomy tag links are not working!?

    https://www.seacole.com/product-search
    https://www.seacole.com/?s=oven

    When you click on a tag or a word in the “Seacole Product Tags:” it should open a new search/list for this word, but we get a page not found. Here is the code that displays this list:

     <span class='post-meta-infos'>
                        <time class='date-container minor-meta updated' <?php avia_markup_helper(array('context' => 'entry_time')); ?>>
                            <?php the_time('d M Y'); ?>
                        </time>
                        <?php
                        if(get_post_type() !== "page")
                        {
                            if ( get_comments_number() != "0" || comments_open() )
                            {
                                echo "<span class='text-sep'>/</span>";
                                echo "<span class='comment-container minor-meta'>";
                                comments_popup_link(  "0 ".__('Comments','avia_framework'),
                                                      "1 ".__('Comment' ,'avia_framework'),
                                                      "% ".__('Comments','avia_framework'),'comments-link',
                                                      "".__('Comments Disabled','avia_framework'));
                                echo "</span>";
                            }
                        }
    
                        $taxonomies  = get_object_taxonomies(get_post_type($the_id));
                        $cats = '';
    					$excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array('post_tag','post_format') );
    					$excluded_taxonomies = apply_filters('avf_exclude_taxonomies', $excluded_taxonomies, get_post_type($the_id), $the_id);
    					
                        if(!empty($taxonomies))
                        {
                            foreach($taxonomies as $taxonomy)
                            {
                                if(!in_array($taxonomy, $excluded_taxonomies))
                                {
                                    $cats .= get_the_term_list($the_id, $taxonomy, '', ', ','').' ';
                                }
                            }
                        }
    
                        if(!empty($cats))
                        {
                            echo "<span class='text-sep'>/</span>";
                            echo '<span class="blog-categories minor-meta">'.__('Seacole Product Tags:','avia_framework')." ";
                            echo $cats;
                            echo '</span>';
                        }
    
                        ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hey @angeladesign,

    Ok I think I have a good handle on what’s happening here.
    The Search bar on your Products page does deliver results, but the tag links underneath do not.

    Let’s use “Bright” as an example:
    If I go to the products page and type in Bright in the search bar, it takes me to the page – https://www.seacole.com/?s=Bright – which displays search results. This page is generated by the WordPress search system automatically based on the keyword entered.
    If I go to the products page and click on the Bright tag link, it takes me to this page – https://www.seacole.com/product/bright/ – which is telling WordPress to find a page called Bright in the back-end, since it doesn’t, you get the error message.

    Would need more time to rewrite your code, essentially you want your tags to direct to the search results page (domain.com/?s=keyword) instead of an actual WordPress page/post.

    Hope that helps ??
    If you absolutely run into a roadblock with updating the code I may have some time over the weekend to help out…

    Thread Starter angeladesign

    (@angeladesign)

    jordanwpcom,
    Thank you! Yes, you are correct on what is happening on the front end… now for a solution in code!??

    So, let’s focus on the tags and the code that is generated under the search results title: https://www.dropbox.com/s/437eqmpz3qkw70t/Screenshot%202017-05-25%2018.53.20.png?dl=0

    Can we make any changes here? Note:see above for the full code

    $cats .= get_the_term_list($the_id, $taxonomy, '', ', ','').' ';

    or here in echo $cats;?

    echo '<span class="blog-categories minor-meta">'.__('Seacole Product Tags:','avia_framework')." ";
                            echo $cats;

    Thanks!

    Hey @angeladesign, sure, I’ll try and help you the best I can!
    The screenshot you supplied doesn’t show the entire code.

    It’s less about generating a link to the search page, and more about passing the tag link keywords through the WordPress search query, then generating the page and linking to it, all automatically.

    How do you have those tags setup? If I’m reading the code correctly you’re using categories?
    I can’t see any easy way of updating your current code to make this work, you may very well need to redo the entire section.

    Or, a less dynamic solution could be to hard-code the links in each tag. So “Bright” links directly to – https://www.seacole.com/?s=Bright – but this would require you to enter the keyword in the search bar, copy the url, and create each link individually.

    Thread Starter angeladesign

    (@angeladesign)

    Hi Jordanwpcom!

    Reaching back out to see if you would be interested in looking at more code!? Do you see anything in this code/file that would cause the search by product tags to generate the NOTHING FOUND page? Thanks!

    function searchProducts()
    {
    	var url = jQuery("#post_url").val() + "&sq=" +jQuery("#s").val();
    	
    	jQuery.ajax({
    		'url' : url,
    		'type' : 'POST',
    		'data' : {action:"getSearchResults"},
    		'success' : function(data){
    			var obj = jQuery.parseJSON(data);
    			if(obj.success) {
    		        // loop the array, and do whatever you want to do
    		        if (jQuery(".searchResults").length > 0) {
    		        	jQuery("#mainSearch").empty();
    		        }
    		        jQuery.each(obj.result, function(key, value){
    		            jQuery("#mainSearch").append(renderElement(jQuery(this)));
    		        });
    		    }
            },
    		error: function (xhr, ajaxOptions, thrownError) {
    			console.log("error");
       		}
    	});
    }
    
    function renderElement (result){
    	var title = result[0];
    	var categories = result[1];
    	var description = result[2];
    	var link = result[3];
    	var tagsTemp = result[4];
    	var tags = "";
    	for (var i = 0; i < tagsTemp.length; i++) {
    		if ((i + 1) === tagsTemp.length) 
    		{
    			tags = tags + tagsTemp[i];
    		} 
    		else
    		{
    			tags = tags + tagsTemp[i] + ",";
    		}
    		
    	}
    	var returnElement = "<a target='_blank' href='"+link+"'><div class='searchResults'><div class='searchTitle'>"+ title + "</div></br><div class='searchCategory'>"+categories+ "</div></br><div class='searchDescription'>" + description + "</div></div></a>";
    	return returnElement;			
    }
    Thread Starter angeladesign

    (@angeladesign)

    register_taxonomy(
    			'product',
    			'seacole_products',
    			array(
    				'label' => __( 'Product' ),
    				'rewrite' => array( 'slug' => 'product' ),
    				'capabilities' => array(
    					'manage__terms' => 'edit_posts',
    				    'edit_terms' => 'manage_categories',
    				    'delete_terms' => 'manage_categories',
    				    'assign_terms' => 'edit_posts'
    				)
    			)
    		);
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search Tag Links Not Working’ is closed to new replies.