Page Title Displaying Incorrectly - wordpress

I have created a custom post type and taxonomy on my website but when I view the taxonomy page it is showing the incorrect page title. Rather than showing 'Taxonomy Term Name' as the Title it is showing the title of the first post shown on that page?
This is my taxonomy page template...
<div class="one-whole">
<!-- Course Tax -->
<?php
// Get the taxonomy
$taxonomy = get_queried_object();
$id = $taxonomy->term_id;
$name = $taxonomy->name;
$slug = $taxonomy->slug;
?>
<h1><?php echo $name; ?> Training Courses</h1>
<?php echo term_description( $id, $name ) ?>
<hr>
<section class="flexbox one-whole">
<?php // Create a custom loop for all items in this taxonomy
$args = array(
'post_type' => 'htl_training',
'posts_per_page' => -1,
'order' => 'asc',
'orderby' => 'name',
'tax_query' => array ( array(
'taxonomy' => 'course-categories',
'terms' => $taxonomy->slug, // Taxonomy Term to Search in
'field' => 'slug',
'operator' => 'IN')
)
);
$posts = new WP_Query($args);
if($posts->have_posts()) :
while($posts->have_posts()) :
$posts->the_post(); ?>
<!-- Card -->
<div class="card card-title-below">
<?php $image = get_field('accrediting_body'); ?>
<?php if( !empty($image) ){ ?>
<?php
// check if the repeater field has rows of data
if( have_rows('endorsing_bodies','options') ){
// loop through the rows of data
while ( have_rows('endorsing_bodies','options') ) {
the_row();
$hook = get_sub_field('logo_hook', 'options');
$icon = get_sub_field('logo','options');
$accrediting_body = get_field('accrediting_body');
if( $accrediting_body ){ ?>
<div class="training-provider">
<?php if( $accrediting_body === $hook ) {
echo '<img src="' . $icon['url'] . '" alt="' . $hook .'" />';
} ?>
</div>
<?php
}
}
} else { } ?>
<?php } ?>
<a href="<?php the_permalink(); ?>" class="non-animated-link">
<?php htl_the_post_thumbnail(); ?>
</a>
<h4><?php the_title(); ?></h4>
</div><!--/ Card -->
<?php
endwhile;
else:
echo' Oops, there are no posts';
endif;
?>
<?php wp_reset_postdata(); ?>
</section>
<!-- Course Tax -->
</div>
How can I show the taxonomy term name as the page title?

Use following function to display archive title
the_archive_title();
More info here

Related

ACF loop for grid, get/display custom field

I'm using this piece of code in my Wordpress template:
<?php
$args = array( 'numberposts' => '12', 'post_type' => 'training', 'post_status' => 'publish' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ) {
echo '<div class="col-xs-12 col-md-4"><article><div class="kartel"><a href="' . get_permalink($recent["ID"]) . '">';
if ( has_post_thumbnail( $recent["ID"]) ) {
echo get_the_post_thumbnail($recent["ID"],'medium');
}
echo '</a></div><h3>' . $recent["post_title"].'</h3> ';
echo '<em>Doelgroep //</em>
<p>One-liner/super korte omschrijving</p>';
echo 'Tell me more ';
echo '</article></div>';
}
wp_reset_query();
?>
Thing is that I now want to add a custom field (let's say 'custom_field') that displays a custom excerpt underneath the thumbnail for the grid. I can get the usual fields (excerpt, title, etc.) but not the custom fields. For example the_field ('custom_field'); isn't working..
Any ideas/suggestions?
Hope to hear from you guys!
Filt
First of all change your approach to queries and Wordpress loops using the WP_Query class.
<?php
$args = array( 'numberposts' => '12', 'post_type' => 'training', 'post_status' => 'publish' );
$loop = new WP_Query($args);
if( $loop->have_posts() ) {
while( $loop->have_posts() ){
$loop->the_post(); ?>
<div class="col-xs-12 col-md-4">
<article>
<div class="kartel">
<a href="<?php the_permalink(); ?>">
<?php if( has_post_thumbnail("medium") ) {
the_post_thumbnail( "medium" );
}
?>
</a>
</div>
<a href="<?php the_permalink(); ?>">
<?php the_title("<h3>","</h3>"); ?>
</a>
<em>Doelgroep //</em>
Tell me more
</article>
</div>
<?php }
}
wp_reset_postdata();
?>
Later, in the loop of your posts, you can recall the custom field using:
the_field ('custom'); //which prints the result on screen
$var = get_field ('custom'); //or echo get_field ('custom') which returns the content in a variable.
If you want to recall a specific custom field inserted in a post or page or custom post type, you must use the following syntax:
the_field ('custom', $ post_id);
get_field ('custom', $ post_id)
That's all :)

Wordpress List Child Pages like a Category

I'm trying to create a page in Wordpress that acts like a Category page listing the child pages. (like it would on the category page). I would like to add a custom field as the excerpt since pages don't have excerpts (unless there's a simple plugin suggestion for this)
I've been trying to merge a few examples, but not getting the correct end result.
<?php if ( is_page( 777 ) ) : ?>
<?php
$mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );
foreach( $mypages as $page ) {
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( 'the_content', $content );
?>
<div class="entry-header"><h2 class="entry-title"><?php echo $page->post_title; ?></h2></div>
<?
$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT');
if ( $child_pages ) :
foreach ( $child_pages as $pageChild ) :
setup_postdata( $pageChild );
$thumbnail = get_the_post_thumbnail($pageChild->ID, 'thumbnail', array( 'class' => 'alignleft' ));
?>
<div class="child-thumb">
<a href="<?= get_permalink($pageChild->ID) ?>" rel="bookmark" title="<?= $pageChild->post_title ?>">
<?= $thumbnail ?>
</a>
</div>
<div class="entry-summary"><?php the_excerpt(); ?></div>
<? endforeach; endif; ?>
<?php } ?>
<?php endif; ?>
Found two simple plugins that do the trick.
https://wordpress.org/plugins/page-list/
https://wordpress.org/plugins/page-excerpt/

get_the_title() is returning results from previous loop

I'm attempting to loop thought a custom post type (artists), then each category, then another custom post type (story) which has a relationship with the artist.
The issue is, the function <?php echo get_the_title( $story->ID ); ?> in the final loop is returning a title of the Artist many times over, along with the title of the current custom post. I just need the title of the currentent loops post.
<!-- get all the artists -->
<?php
$args = array(
'post_type' => 'artists'
);
$query = new WP_QUERY( $args );
?>
<?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_field('artist_website'); ?></p>
<!-- looping through all the categories -->
<?php
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat) {
// setup the cateogory ID
$cat_id= $cat->term_id;
// Make a header for the cateogry
echo "<h2>".$cat->name."</h2>";
?>
<!-- looping through the stories that have a relationship with the artist (select_artist) -->
<?php
$post_type = 'story';
$args = array(
'post_type' => $post_type,
'posts_per_page' => -1, //show all posts
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $cat->slug,
)
),
'meta_query' => array(
array(
'key' => 'select_artist', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123.
'compare' => 'LIKE'
)
)
);
$stories = new WP_Query($args);
?>
<?php if( $stories ): ?>
<ul>
<?php foreach( $stories as $story ): ?>
<!-- Problem echo below -->
<?php echo get_the_title( $story->ID ); ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php } // done the foreach statement ?>
<?php endwhile; wp_reset_postdata(); endif; ?>
</section>
If you're using WP_Query you should be using a while loop and end with the_post() in order to set up the internal variables that would allow get_the_title() to work properly.
As an added measure you could set the $post variable to a $temp variable before your inner loop, then reset back after.
<?php
$stories = new WP_Query($args);
if( $stories->have_posts() ):
global $post;
$temp = $post;
?>
<ul>
<?php
while( $stories->have_posts() ): $stories->the_post();
the_title();
endwhile;
$post = $temp;
?>
<ul>
<?php endif; ?>

Display Posts Category Wise

I have code to show the latest 3 posts of every category and I want to exclude the child categories, but it doesn't exclude the sub category and it shows sub category separately and it show the latest 3 posts of sub category. Is there any way to exclude sub categories from loop.
Here is the code:
<?php
//start page loop
if (have_posts()) : while (have_posts()) : the_post();
//get meta to set parent category
$library_filter_parent = '';
$library_parent = get_post_meta($post->ID, 'wts_library_parent', true);
if($library_parent != 'select_library_parent') { $library_filter_parent = $library_parent; } else { $library_filter_parent = NULL; }
?>
<div id="library-by-category-wrap">
<?php
//get meta to set parent category
$library_filter_parent = '';
$library_parent = get_post_meta($post->ID, 'wts_library_parent', true);
if($library_parent != 'select_library_parent') { $library_filter_parent = $library_parent; } else { $library_filter_parent = NULL; };
//term loop
$terms = get_terms('library_cats','orderby=custom_sort&hide_empty=1&child_of='.$library_filter_parent.'');
foreach($terms as $term) { ?>
<div class="heading">
<h2><?php echo $term->name; ?></h2>
</div>
<div class="library-category">
<?php
//tax query
$tax_query = array(
array(
'taxonomy' => 'library_cats',
'terms' => $term->slug,
'field' => 'slug'
)
);
$term_post_args = array(
'post_type' => 'library',
'numberposts' => '3',
'tax_query' => $tax_query
);
$term_posts = get_posts($term_post_args);
//start loop
foreach ($term_posts as $post) : setup_postdata($post);
//get images
$featured_image = get_the_post_thumbnail($post->ID, 'cat-thumbnail'); ?>
<?php if(!empty($featured_image)) { ?>
<div class="library-item">
<a class="library-title" href="#" title="<?php the_title(); ?>" target="_blank">
<h3><?php the_title(); ?></h3>
</a>
</div>
<!-- /library-item -->
<?php } ?>
<?php endforeach; ?>
</div>
<!-- /library-category -->
<?php } wp_reset_postdata(); ?>
</div>
<!-- /library-by-category-wrap -->
<?php wp_reset_query(); ?>
<?php endwhile; endif; ?>
<?php
//get all terms (e.g. categories or post tags), then display all posts in each term
$taxonomy = 'category';// e.g. post_tag, category
$param_type = 'category__in'; // e.g. tag__in, category__in
$term_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
foreach( $terms as $term ) {
$args=array(
"$param_type" => array($term->term_id),
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List of Posts in '.$taxonomy .' '.$term->name;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><?php the_title(); ?></p>
<?php
endwhile;
}
}
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
Note see the Time Parameters in the query_posts() article.
<?php // get all the categories from the database
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat) {
// setup the cateogory ID
$cat_id= $cat->term_id;
// Make a header for the cateogry
echo "<h2>".$cat->name."</h2>";
// create a custom wordpress query
query_posts(“cat=$cat_id&post_per_page=100");
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php // create our link now that the post is setup ?>
<?php the_title(); ?>
<?php echo '<hr/>'; ?>
<?php endwhile; endif;
// done our wordpress loop. Will start again for each category ?>
<?php } // done the foreach statement ?>
<?php
$catquery = new WP_Query( array( 'post_type' => 'testimonials', 'category_name'=>'hello','posts_per_page' => 10 ) );
while($catquery->have_posts()) : $catquery->the_post();
?>
<ul>
<li>
<h3>
<?php the_title(); ?>
</h3>
</li>
<li>
<?php the_content(); ?>
</li>
</ul>
<?php endwhile; ?>
$taxonomy = 'category';
$term_args = array(
'orderby' => 'name',
'order' => 'ASC',
'parent' => 0
);
$terms = get_terms($taxonomy, $term_args);
[homepage_cat_grid limit='3' cat_id='2']
add_shortcode( 'homepage_cat_grid', array($this, 'homepage_postgrid_shortcode') );
/**
* HOME PAGE CATEGORY WISE POST GRID
*/
public function homepage_postgrid_shortcode( $atts, $content ) {
extract( shortcode_atts( array (
'order' => '',
'orderby' => '',
'limit' => '',
'cat_id'=> ''
), $atts ) );
ob_start();
$args = array(
'post_type' => 'post',
'order' => $order,
'orderby' => $orderby,
'posts_per_page' => $limit,
'cat' => $cat_id
);
$home_post = new WP_Query( $args );
if( $home_post->have_posts() ) : ?>
<div class="post-header">
<div class="head-left">
<?Php
$terms = wp_get_post_terms($home_post->post->ID,'category');
$cat_nm=$terms[0]->name;
if($cat_nm=='News'): echo "Recent News"; else: echo $cat_nm; endif;
?>
</div>
<a href="<?php
$category_link = get_category_link( $terms[0]->term_id );
echo $category_link; ?>" class="btn post-head-btn">VIEW ALL</a>
</div>
<div class="row">
<?php while ( $home_post->have_posts() ) : $home_post->the_post(); ?>
<div class="col-md-4">
<div class="single-grid">
<a href="<?php echo get_permalink( $post->ID ); ?>">
<?php the_post_thumbnail( $post->ID ); ?>
</a>
<div class="post-caption">
<?php echo the_category(); ?>
<div class="post-heading">
<?php echo the_title(); ?>
</div>
<div class="post-content">
<?php the_excerpt(); ?>
</div>
<div class="row">
<div class="col-12">
<a class="btn btn-dark cust-btn" href="<?php echo get_permalink( $post->ID ); ?>">Read More</a>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
<?php else :
get_template_part( 'template-parts/content', 'none' );
endif;
return ob_get_clean();
}

Shortcode rendering as text not as shortcode should

I am building a shopping website and I am trying to put a shortcode in that will show the customer a buy button and the quantity of the product the customer wants to purchase. On my post page the shortcode works fine:
http://warringah-plastics.com.au/blog/dt_catalog/recess-gasket-large/
but on the archive page:
http://warringah-plastics.com.au/store/
the shortcode id displayed as text and not the actual button and quantity e.g. [add_to_cart item="FPROWAR-160713-1" showprice="no" quantity="user:1" ajax="yes" ].
The code that works in the post page is this:
<?php
$my_textbox_value = mtbxr_val("shopping_shortcode");
echo do_shortcode("$my_textbox_value");
?>
but it just displays the shortcode text on that archive page. Anyone have any ideas? Much appreciated,
UPDATE
THIS IS THE CODE THAT DISPLAYS THE SHORTCODE CORRECTLY:
<?php get_header(); ?>
<?php dt_storage('have_sidebar', true); ?>
<?php get_template_part('top-bg'); ?>
<?php get_template_part('parallax'); ?>
<div id="wrapper">
<?php get_template_part('nav'); ?>
<div id="container">
<?php if( have_posts() ): while( have_posts() ): the_post(); ?>
<h1><?php the_title(); ?></h1>
<h1 style="color: #3C3C3B !important; margin-top:-20px !important;"><?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'dt_catalog_category', '', ', ', '' ) );
echo $terms_as_text; ?></h1>
<?php
global $post;
$post_opts = get_post_meta($post->ID, '_dt_catalog-post_options', true);
if( !isset($post_opts['hide_media']) || (isset($post_opts['hide_media']) && !$post_opts['hide_media']) ) {
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC'
);
if( !empty($post_opts['hide_thumbnail']) )
$args['post__not_in'] = array( get_post_thumbnail_id() );
$dt_tmp_query = new WP_Query( $args );
if( $dt_tmp_query->have_posts() ) {
$slides = array();
foreach( $dt_tmp_query->posts as $slide ) {
$video = get_post_meta( $slide->ID, '_dt_catalog_video_link', true );
$tmp_arr = array();
$tmp_arr['caption'] = $slide->post_excerpt;
if ( ! $video ) {
$slide_src = dt_get_resized_img( wp_get_attachment_image_src( $slide->ID, 'full' ), array( 'w' => 710 ) );
$tmp_arr['alt'] = get_post_meta( $slide->ID, '_wp_attachment_image_alt', true );
$tmp_arr['src'] = $slide_src[0];
$tmp_arr['size_str'] = $slide_src[3];
} else {
$tmp_arr['is_video'] = true;
$tmp_arr['src'] = $video;
$tmp_arr['size_str'] = array( 710, 1024 );
}
$slides[] = $tmp_arr;
}
dt_get_anything_slider( array( 'id' => 'slider2', 'items_arr' => $slides ) );
}
}
?>
<?php $opts = get_post_meta($post->ID, '_dt_catalog-goods_options', true); ?>
<?php if( !empty($opts['price']) ): ?>
<span class="price"><?php _e('Price: ', LANGUAGE_ZONE); echo esc_html($opts['price']); ?></span>
<?php endif; ?>
<?php
$my_textbox_value = mtbxr_val("shopping_shortcode");
echo do_shortcode("$my_textbox_value");
?>
<?php
the_content();
if( dt_is_page_soc_buttons_enabled('catalog') ) {
dt_get_like_buttons( get_the_ID() );
}
?>
<?php if( !empty($opts['p_link']) ): ?>
<span><i class="dol"></i><?php _e('Make purchase!', LANGUAGE_ZONE); ?></span>
<?php endif; ?>
<p class="gap"></p>
<?php
$rel_works = get_post_meta($post->ID, '_dt_catalog_related', true);
if( isset($rel_works['show_related']) && $rel_works['show_related'] ):
if( 'same' == $rel_works['related'] ) {
$rel_works['related'] = wp_get_post_terms(
$post->ID,
'dt_catalog_category',
array('fields' => 'ids')
);
}
if( !empty($rel_works['related']) ):
?>
<p class="hr hr-narrow gap-small"></p>
<div class="gap"></div>
<div class="full-width w-photo">
<h2><?php _e('Related Items', LANGUAGE_ZONE); ?></h2>
<?php
if( 'same' == $rel_works['related'] ) {
$rel_works['related'] = wp_get_post_terms(
$post->ID,
'dt_catalog_category',
array('fields' => 'ids')
);
}
$dt_tmp_query = new WP_Query( array(
'posts_per_page' => -1,
'post_type' => 'dt_catalog',
'post_status' => 'publish',
'post__not_in' => array($post->ID),
'tax_query' => array( array(
'taxonomy' => 'dt_catalog_category',
'field' => 'id',
'terms' => $rel_works['related'],
'operator' => 'IN'
) )
) );
if( $dt_tmp_query->have_posts() ) {
$thumb_arr = dt_core_get_posts_thumbnails( $dt_tmp_query->posts );
$items = array();
foreach( $dt_tmp_query->posts as $rel_post ) {
$item = array();
$img = dt_get_resized_img(
dt_get_thumb_meta($thumb_arr['thumbs_meta'], 'full', $rel_post->ID),
array('w' => 196, 'h' => 123, 'use_noimage' => true)
);
$item['src'] = $img[0];
$item['size_str'] = $img[2];
$item['post_id'] = $rel_post->ID;
$item['desc'] = apply_filters('get_the_excerpt', $rel_post->post_excerpt);
$item['title'] = apply_filters('the_title', $rel_post->post_title, $rel_post->ID);
$item['alt'] = esc_attr( $item['title'] );
$items[] = $item;
}
$args = array( 'items_arr' => $items, 'id' => '', 'class' => 'list-carousel recent bx', 'ul_class' => 'slider1' );
$args['wrap'] = '<div class="%CLASS% bx">%SLIDER%</div>';
if( ! empty( $rel_works['show_desc'] ) || ! empty( $rel_works['show_title'] ) ) {
$title = '';
if( ! empty( $rel_works['show_title'] ) ) {
$title = '<h3>%TITLE%</h3>';
}
$desc = '';
if( ! empty( $rel_works['show_desc'] ) ) {
$desc = '<p>%DESC%</p>';
}
$args['item_wrap'] = '
<li>
<div class="textwidget">
<div class="textwidget-photo">
<a class="photo" href="%LINK%"><img src="%IMG_SRC%" alt="%ALT%" %IMG_SIZE% /></a>
</div>
<div class="widget-info">
<div class="info">
' . $title . $desc . '
</div>
</div>
</div>
</li>
';
}
dt_get_carousel_slider( $args );
}
?>
</div>
<?php endif; endif; ?>
<?php comments_template(); ?>
<?php
endwhile;
endif;
?>
</div>
<?php dt_widget_area('sidebar', null, 'sidebar_4'); ?>
</div>
<?php get_footer(); ?>
AND THIS IS THE CODE THAT DISPLAYS THE SHORTCODE JUST AS TEXT:
<?php
global $post;
$page_data = dt_storage( 'page_data' );
$page_opts = ! empty( $page_data['page_options'] ) ? $page_data['page_options'] : array();
$add_data = dt_storage( 'add_data' );
$first_class = '';
if( 1 === dt_storage('post_is_first') ) {
$first_class = ' first';
dt_storage( 'post_is_first', -1 );
}
$opts = get_post_meta($post->ID, '_dt_catalog-goods_options', true);
?>
<div class="<?php dt_portfolio_classes( '2_col-list', 'block' ); echo $first_class; ?>">
<?php
$h = 220;
if ( ! empty ( $page_opts['thumb_height'] ) ) {
$h = $page_opts['thumb_height'];
}
dt_get_thumb_img( array(
'class' => 'photo',
'use_noimage' => true,
'href' => get_permalink(),
'thumb_opts' => array( 'w' => 343, 'h' => $h )
),
'<div class="textwidget-photo">
<a %HREF% %CLASS% %TITLE% %CUSTOM%><img %ALT% %SRC% %IMG_CLASS% %SIZE% /></a>
</div>'
);
?>
<div class="<?php dt_portfolio_classes( '2_col-list', 'info' ); ?>">
<a class="<?php dt_portfolio_classes( '2_col-list', 'head' ); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php if( !empty($opts['price']) ): ?>
<span class="price"><?php _e('Price: ', LANGUAGE_ZONE); echo esc_html($opts['price']); ?></span>
<?php endif; ?>
<?php
dt_the_content();
dt_details_link();
dt_edit_link();
?>
<div id="specialpriceshortcode">
<?php
$my_textbox_value = mtbxr_val("shopping_shortcode");
echo do_shortcode("$my_textbox_value");
?>
</div>
</div>
</div>
Try using single quotes in the do_shortcode call, like so:
echo do_shortcode('$my_textbox_value');
More likely though is that the shortcode isn't defined on the archive page so you'd need to look at where it is being instantiated to see if that is the issue. Normally when a shortcode just echoes out the content it means that shortcode doesn't exist. You can test easily enough by using the shortcode_exists() function:
<?php if ( shortcode_exists( 'add_to_cart' ) ) { echo "The shortcode exists";} ?>
If that doesn't work then you know the issue is with the shortcode not being registered on your archives page. If it does work then you know it's something with the format of the content being passed to the shortcode.
Add this to your functions.php
// Allow shortcodes on widgets
add_filter('widget_text','do_shortcode');
// Allow shortcodes on pages (not tested, but should work)
add_filter('the_content','do_shortcode');
Typically your shortcode is getting registered in a plugin or your theme's functions.php file. In a plugin it's often something like:
add_action('init', 'register_my_shortcode');
function register_my_shortcode(){
add_shortcode('my_shortcode', 'do_my_shortcode');
}
And then you'd have a function do_my_short_code() that actually outputs the content. With something like that the shortcode is getting registered via the 'init' hook (http://codex.wordpress.org/Plugin_API/Action_Reference) which is called before WP has started figuring out what template to use, what content to output, etc.
But some plugins will register the shortcode in a way that it is only available on pages / posts where it's going to potentially be used. For example, I can think of one plugin where they register the shortcode and enqueue some javascripts in the same function. That function checks to see if you're on a particular page before it executes so that the js files are not included unnecessarily all over the place. Since the shortcode registration takes place in the same function it means the shortcode only exists on those pages.
Anyhow, if the shortcode is showing as existing on your archives page you know that isn't the problem, so check that first and let me know what you find.

Resources