• Hi,
    I have pages that contain shortcode , via the shortcode the content is displayed in the page, means i need a tabbed content in my pages , so i used a plugin and added tabs and content in the plugin pages. then used the respective shortcode in every pages. so the page with that shortcode is not listing in my search results page. only listing the pages with content that is written in text editor of page if the keyword searched is matching. if the keyword is present in the content generated by shortcode will not included in the search query, how can i achieve this?
    Please help me ASAP

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s not clear what you want. Do you want shortcode content included or excluded from search criteria? Normal behavior excludes it because shortcode content is not included in the DB records that are searched. So you want shortcode content included in the search?

    Success depends on where the shortcode is getting it’s content. Unless this location can be related via SQL to the post where it appears, such a search may not be possible. The simplest solution is to include search keywords in shortcode attributes so the keywords appear in post content data in the DB, independent of actual shortcode content. Unexpected attribute values are ignored by shortcode handlers.

    Otherwise, the search SQL would need to be altered to relate the shortcode content location to the post in which it occurs.

    Thread Starter safnasash

    (@safnasash)

    thanks for the reply, i need to include the contents from the shortcode.

    i found that the content is stored in post meta table as meta value, so how can i get the page that contains the shortcode that will generate this content.

    in post_content ,shortcode is there, in wp_postmeta, the content generated by that shortcode is stored in meta value. so is it possible to get that page ?

    Moderator bcworkz

    (@bcworkz)

    For any given shortcode content in postmeta, does that record’s post_id value always relate directly back to the post in which the related shortcode lives? In similar schemes like this it’s not the case. It’s an important requirement for getting a successful search query.

    WP_Query does support LIKE meta queries, however the usual search query is a little odd in how it’s handled. The resulting SQL will need modification after a meta query is added to a search query. You can add the “meta_query” arg through the “pre_get_posts” action. Your callback would verify a search query is being made. If so, get the search criteria from the “s” query var and set the “meta_query” query var to be something like

    array(
    		array(
    			'key'     => 'shortcode_content',
    			'value'   => $search_criteria,
    			'compare' => 'LIKE',
    		),
    	)

    The problem with the resulting SQL in doing this is the meta criteria will be logically ANDed with the normal search criteria. You need OR logic, so your callback also needs to hook the “posts_where” filter with another callback that will find the offending AND in the SQL WHERE clause and change it to OR.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘page with content generated by shortcode is not listing in search results page’ is closed to new replies.