• I’ve been searching for the best part of a day on the forums but just cannot understand why this is happening…

    I have created a “Portfolio” custom post in which I wish to insert posts under different categories (or “type” as I’ve called it). It’s a photography website and I currently have just two categories for testing purposes: “landscape” and “cityscape”. I want to put links to each post manually (i.e. outside of any loop) in a menu or on a page. I understand that I need to use the get_term_link() function but if I put the below in my menu then the page loads without any errors but only loads up until the third list item (where I use the get_term_link function). The forth list item does not display and, more strangely, if I click on the ‘home’ link the blog page does not load (page just reloads as is). If I remove the get_term_link item from the menu, the page loads completely and the ‘home’ takes me to the blog page as I would expect.

    I have no idea why this is happening since I think the code is right — any help/suggestions would be very much appreciated!!

    <div id="menu">
    <ul id="menu">
    
    <li><a>">Blog</a></li>
    <li><a>">Gallery</a></li>
    <li><a>">Landscapes</a></li>
    <li><a href="?page_id=13">Guide</a></li>
    </div><!-- #menu -->
    
    ---------------------------------
    //In function.php file...
    
    add_action('init', 'portfolio_register');
    
    function portfolio_register() {
    
    	$labels = array(
    		'name' => _x('Portfolio', 'post type general name'),
    		'singular_name' => _x('Portfolio Item', 'post type singular name'),
    		'add_new' => _x('Add New', 'portfolio item'),
    		'add_new_item' => __('Add New Portfolio Item'),
    		'edit_item' => __('Edit Portfolio Item'),
    		'new_item' => __('New Portfolio Item'),
    		'view_item' => __('View Portfolio Item'),
    		'search_items' => __('Search Portfolio'),
    		'not_found' =>  __('Nothing found'),
    		'not_found_in_trash' => __('Nothing found in Trash'),
    		'parent_item_colon' => ''
    	);
    
    	$args = array(
    		'labels' => $labels,
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => 5,
    		'supports' => array('title','editor','thumbnail'),
    		'has_archive' => true,
    	  ); 
    
    register_post_type( 'portfolio' , $args );}
    
    register_taxonomy("Type", array("portfolio"), array("hierarchical" => true, "label" => "Type", "singular_label" => "Type", "rewrite" => true));
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter tokyobear

    (@tokyobear)

    Code for the menu should read:

    <li><a href="<?php echo get_settings('home');?>">Blog</a></li>
    <li><a href="<?php echo get_post_type_archive_link('portfolio');?>">Gallery</a></li>
    <li><a href="?page_id=13">Guide</a></li>
    Thread Starter tokyobear

    (@tokyobear)

    And like so for the full code with the get_term_link error:

    <li><a href="<?php echo get_settings('home');?>">Blog</a></li>
    <li><a href="<?php echo get_post_type_archive_link('portfolio');?>">Gallery</a></li>
    <li><a href="<?php echo get_term_link('Landscapes','Portfolio');?>">Landscapes</a></li>
    <li><a href="?page_id=13">Guide</a></li>
    Thread Starter tokyobear

    (@tokyobear)

    Update…

    If I change

    get_term_link('Landscapes','Portfolio');

    to

    get_term_link('Landscapes','Type');

    … then the page loads correctly. But it displays ALL photographs loaded into a portfolio post and not just the ones with the type/category ‘landscapes’…

    Feel I’m missing something obvious…

    Thread Starter tokyobear

    (@tokyobear)

    Making slow progress — will post in the hope that someone can push me over the line (relatively new to WP and PHP…).

    I can achieve what I want but is it really the case that for every new category I create in my custom post I have to create a file called..

    taxonomy-type-[insert category… landscape/cityscape, etc.].php

    …?

    If that’s the case, so be it. Otherwise, I’d appreciate someone pointing me in the right direction. Thanks.

    Thread Starter tokyobear

    (@tokyobear)

    Solved…

    <?php $args = array( 'post_type' => 'portfolio', 'taxonomy' => 'Type', 'term' => $_GET['type'], 'posts_per_page' => 20 );?>
    <?php $loop = new WP_Query( $args );?>

    The above in taxonomy-type.php

    And then I take the term from the link…

    <a href="<?php echo get_term_link('Landscapes', 'Type');?>">Landscapes</a>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘get_term_link stops rest of website from loading’ is closed to new replies.