Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter jasongeiger

    (@jasongeiger)

    Saku4388

    The best way to go about it is to run custom sql queries for what you want to retrieve.

    I would recommend looking through some of the custom queries that have been given above to get familiar with custom sql queries.

    The thing is: grabbing tags and categories is already pretty intense to follow, adding post meta is only going to make it more difficult because you are adding another table to the mix.

    Good Luck!

    Thread Starter jasongeiger

    (@jasongeiger)

    The goal of this was to be able to batch tags based on the category to develop a category specific list of tags, which in turn linked to that tags filtered archive.

    Thread Starter jasongeiger

    (@jasongeiger)

    This what I’ve come up with. I think apljdi, is right about custom query. This still seems a bit excessive.

    <?php
            $project_query = query_posts('category_name=projects');
            while (have_posts()) : the_post();
                $posttags = get_the_tags();
                if ($posttags) {
                    foreach($posttags as $tag) {
                        $all_tags_arr[] = $tag -> name; //USING JUST $tag MAKING $all_tags_arr A MULTI-DIMENSIONAL ARRAY, WHICH DOES WORK WITH array_unique
                    }
                }
            endwhile;
        ?>
        <?php if ( is_array($all_tags_arr) && count($all_tags_arr) > 0 ): ?>
    <?php
        $tags_arr = array_unique($all_tags_arr); //REMOVES DUPLICATES
        foreach( $tags_arr as $tag ):
            $el = get_term_by('name', $tag, 'post_tag');
    		$arr[] = '"tag-'.$el->slug.'"';
        ?>
        <span><a href="#<?php echo $el->slug; ?>" id="taglink-tag-<?php echo $el->slug; ?>" rel="tag-<?php echo $el->slug; ?>"><?php echo $el->name; ?></a> <span class="slash">//</span></span>
    <?php endforeach; ?>

    greenshady, that works great.

    I’m wonder how to extend it to include the default templates like: archive, single, search, etc.

    Thread Starter jasongeiger

    (@jasongeiger)

    Electric Studio, that’s not exactly what I was looking for but it was good stepping stone.

    <?php
    	query_posts('category_name=work');
    	if (have_posts()) : while (have_posts()) : the_post();
            $posttags = get_the_tags();
    		if ($posttags) {
    			foreach($posttags as $tag) {
    				$all_tags_arr[] = $tag -> name; //USING JUST $tag MAKING $all_tags_arr A MULTI-DIMENSIONAL ARRAY, WHICH DOES WORK WITH array_unique
    			}
    		}
    	endwhile; endif; 
    
    	$tags_arr = array_unique($all_tags_arr); //REMOVES DUPLICATES
    	echo '<pre>'.print_r($tags_arr, true).'</pre>'; //OUTPUT FINAL TAGS FROM CATEGORY
    
    ?>

    This does the job, except it would be nice to have $tags_arr as a multi-dimensional array but that does work with array_unique.

    Still my question is, if you have say 100 posts in a category, is doing query like this the most efficient way of getting these results.

Viewing 5 replies - 1 through 5 (of 5 total)