• Resolved ThomasLG

    (@thomaslg)


    The widget works fine on single pages and the blog overview page, but in tag and category templates, it’s empty, returning nothing. Tried using the shortcode as well, still nothing returned (only title is present, none of the links). Seems to be some issue related to the main post query. If I run the shortcode [simple-links] without any options, it returns a long list of posts (not links!). Tried using wp_reset_query(); in the template, before using the widget/shortcode, still no go. Displaying PHP errors gives me nothing relevant. Neither any js errors. Running var_dump on $simple_links gives me an empty object.

    Not sure what to do next to troubleshoot this, do you have any tips?

    https://www.ads-software.com/plugins/simple-links/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mat Lipe

    (@mat-lipe)

    Hi Thomas,

    It sounds like something is overriding the query when the simple_links are being retrieved.

    It could be another widget or something within the the theme’s template. It could also be another plugin.

    Things to look for.

    • filters or actions on ‘pre_get_posts’
    • filters on ‘post_results’
    • Any WP_Query() within the theme files without a wp_reset_query() at the end

    Because it is isolated to your archives and tags, I would take a look at your theme’s archive and tags template first, especially if there are any custom loops within.

    Otherwise if you are using any filters on the simple links outputs etc. You could try removing those and see if it is related to one of those.

    Hope this helps

    Thread Starter ThomasLG

    (@thomaslg)

    Aha, thanks. I seem to have found the issue, which is with a pre_get_posts filter in my functions.php file. Is there any way to avoid the issue without having to remove the filter altogether? Tried adding ‘simple_links’ in the post_type array, without any luck…

    add_filter('pre_get_posts', 'query_post_type');
    function query_post_type($query) {
      if(is_category() || is_tag()) {
        $post_type = get_query_var('post_type');
    	if($post_type)
    	    $post_type = $post_type;
    	else
    	    $post_type = array('nav_menu_item','post','aktuelt', 'blogg');
        $query->set('post_type',$post_type);
    	return $query;
        }
    }
    Plugin Author Mat Lipe

    (@mat-lipe)

    Hi Thomas,

    You could check for simple links and return if found like so

    add_filter('pre_get_posts', 'query_post_type');
    function query_post_type($query) {
    	if( !empty( $query->query[ 'post_type' ] ) &&  ($query->query[ 'post_type' ] == 'simple_link' ) ){
    		return $query;
    	}
    
    	if( is_category() || is_tag()  ) {
    		$post_type = get_query_var('post_type');
    		if($post_type)
    			$post_type = $post_type;
    		else
    			$post_type = array('nav_menu_item','post','aktuelt', 'blogg');
    		$query->set('post_type',$post_type);
    		return $query;
    	}
    }

    Thread Starter ThomasLG

    (@thomaslg)

    Thanks a lot, that seems to work fine ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Empty on tag/category pages’ is closed to new replies.