Okay
  Public Ticket #2992377
SEO, Tags and Search
Closed

Comments

  •  2
    publicspace started the conversation

    Hi Zhivko

    I have been working on this Calendar system for many days, and I have only just realised that the Events do not show up on the general Search bar on the website.  Is it possible to fix that so that people searching will find Events? 

    I have also realised that the Keywords for the Events do not appear as Tags on the site. So when people click on tags in the Tag Cloud, to see all the posts with a particular key word, they will not see the Events.  

    These both seem hugely important for people using the site, and for the visibility of the Events on Google.  Is it possible to make them work? 

  •   publicspace replied privately
  •  793
    Zhivko replied

    Hi,

    The events by default are not excluded from the general search. Does your search include all post types? The events are  using custom post type "stec_event".

    However, the keywords are working only for in-calendar search only and unfortunately I don't see how it can be done in the current version 3.x.


    Stachethemes Developer

  •  2
    publicspace replied

    Search query - solved.  Thank you.  As you say, it is an issue of what types of posts the search bar is set to search for. In case others have the same question, this is the code snippet I have used, below, inserting 'stec_event' as a third post type. 

    Tags query - Is it possible to add another field for Tags, so they can be picked up in the same way as other posts?  

    /* From: https://www.dhirenpatel.me/cpt-wordpress-search-result/ */
    function include_cpt_search( $query ) {
        
        if ( $query->is_search ) {
            $query->set( 'post_type', array( 'post', 'page', 'stec_event' ) );
        }
        
        return $query;
        
    }
    add_filter( 'pre_get_posts', 'include_cpt_search' );
    

  •  2
    publicspace replied

    Just to add - this code to include STEC Events in the results of general searches on the front end of the website needs to be set to "Only run on site front end".  (That is easy using the Code Snippets plugin). Otherwise it stops the media search working at the back end.  

  •  2
    publicspace replied

    Hi Zhivko

    The code you provided (below) still works well - to include stec events in a search query.  Thank you.

    However, I realise the search results include unpublished events, whereas they only include published posts.  So I want to ask - is there a way to modify the code so that the results include only published stec events? 

    Thank you and best wishes

  •  793
    Zhivko replied

    You can try this one:

    function include_cpt_search($query) {
        if ($query->is_search) {
            $query->set('post_type', array('post', 'page', 'stec_event'));
            $query->set('meta_query', array(
                'relation' => 'OR',
                array(
                    'key'     => 'approved',
                    'value'   => '1',
                    'compare' => '='
                ),
                array(
                    'key' => 'approved',
                    'value' => 'NOT EXIST'
                )
            ));
        }     return $query;
    } add_filter('pre_get_posts', 'include_cpt_search');



    Stachethemes Developer

  •  2
    publicspace replied

    It seems to work...!  

    This could be useful in the next update, because I'm sure most sites would want to include published events in the search.  

    Thank you and best wishes

    Simon