Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2860
    Mark Townsend
    Participant

    Hi

    Can you help with this problem please?

    I am using this plugin with a theme I have bought, that has a widget to show category posts on it’s home page.

    The widget lets you select the category you want to display. I have created categories in your plugin called ‘Our News’ and have added stories for this category. (In the settings I have checked ‘News in Tags & Categories’)

    However, what seems to be happening, is that posts created by the News plugin don’t show up under categories with the wordpress posts section. So, if i create a regular wordpress post (not through the News plugin) and assign the category ‘Our News’ it shows up throughout the site – like a regular category should.

    What i need is for the posts created using the News plugin to transfer to the main site so that if i want the news posts to show somewhere on the site, they do.

    I hope this is explained ok? I’m not a full on developer, but happy to access any php files and mess with code.

    Thanks in advance

    #2862
    Bartosz
    Keymaster

    Hi Mark,

    Great website and portfolio, congrats :) (I looked at it in the meantime)

    I think I understand what you need, but could you post a link to your site too? – I’d like to see how it looks and where (and how) news are used.

    #2863
    Mark Townsend
    Participant
    This reply has been marked as private.
    #2865
    Bartosz
    Keymaster

    Option “News in Tags & Categories” is basically a query modification fired when appropriate options are enabled, you’re viewing a category or post_tag archive and the main query is being displayed so it won’t work here.

    The solution is either to modify the widget you mentioned or to modify the query again with less strict attributes.

    Try this:

    function df_modify_posts_query($query) {
    	if ( !is_admin() && empty($query->query_vars['suppress_filters']) ) {
    		if(($post_type = $query->get('post_type')) === '')
    				$post_type = array('post', 'news');
    		elseif(is_array($post_type))
    		{
    			$post_type[] = 'post';
    			$post_type[] = 'news';
    		}
    		else
    			$post_type = '';
    
    		$query->set('post_type', $post_type);
    	}
    }
    add_action('pre_get_posts','df_modify_posts_query');
    

    If you experience problems try adding an action lower priority like that (because one query modification is already used in the plugin):

    add_action('pre_get_posts','df_modify_posts_query', 20, 1);
    

    That action filter is the key for solving the issue.

    #2866
    Mark Townsend
    Participant
    This reply has been marked as private.
    #2867
    Bartosz
    Keymaster

    Just paste it into functions.php in your theme. And please read about the ‘pre_get_posts’ action hook – it would allow you to make further adjustments if needed.

    #2869
    Mark Townsend
    Participant

    Hi, I tried this and it ended up adding all post types to the ‘testimonials’ section, and didn’t appear in the ‘client news’ section. :(

    Sorry to ask again – might you have a reason for this? Thanks

    #2872
    Bartosz
    Keymaster

    In that case you remove the code I provided and modify that in query_posts var in code:

    from:

    if($dynamic_from_where == 'all_cat'){
                $query_post = array('posts_per_page'=> $posts_per_page, 'post_type'=> 'post' );                          
            }else{
               $query_post = array('posts_per_page'=> $posts_per_page, 'post_type'=> 'post', 'cat' => $dynamic_cat );
    

    to:

    if($dynamic_from_where == 'all_cat'){
                $query_post = array('posts_per_page'=> $posts_per_page, 'post_type'=> array('post', 'news') );                          
            }else{
               $query_post = array('posts_per_page'=> $posts_per_page, 'post_type'=> array('post', 'news'), 'cat' => $dynamic_cat );
    
    #2873
    Mark Townsend
    Participant

    Excellent! that’s done it. Many thanks for your quick and sustained support.

    #4717
    Ehsan Ahmed
    Participant

    Hi,
    I have experiencing same problem in my web site, I have used tags and categories enabled by “News tag” and “News Categories”, using this setup I could not see the categories i beside “Posted in” it just show “Posted in”, “Tagged with” is showing but link is not working…

    I used your given function in function.php

    function df_modify_posts_query($query) {
    	if ( !is_admin() && empty($query->query_vars['suppress_filters']) ) {
    		if(($post_type = $query->get('post_type')) === '')
    				$post_type = array('post', 'news');
    		elseif(is_array($post_type))
    		{
    			$post_type[] = 'post';
    			$post_type[] = 'news';
    		}
    		else
    			$post_type = '';
    
    		$query->set('post_type', $post_type);
    	}
    }
    add_action('pre_get_posts','df_modify_posts_query', 20, 1);
    

    But the selected news from manager switch to post list…

    #4720
    Bartosz
    Keymaster

    Ehsan, this is a completely different issue. Please post a separate topic.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.