• Resolved JelStein

    (@jelstein)


    On my installation when using the shortcode ? include_cat_IDs ? works incorrect

    I can only work with two categories : cat_ID 10 and 6
    All other values like 36 or 4051 do not work…

    this is the one that works:

    [tptn_list heading=’0′ how_old=14 include_cat_ids=”10″ show_date = ‘1’ limit=’5′ disp_list_count = ‘0’]

    please advise

Viewing 15 replies - 1 through 15 (of 23 total)
  • Plugin Author WebberZone

    (@webberzone)

    It should be in small so include_cat_ids

    https://webberzone.com/support/knowledgebase/top-10-shortcodes/

    Thread Starter JelStein

    (@jelstein)

    I only wrote ID in capitals in my text NOT in the shortode parameters (see my example)

    It really does not work!

    Plugin Author Ajay

    (@ajay)

    Can you please let me know what you’re expecting to see and what you see?

    This should limit the posts to only the ones in those categories. Are you seeing posts from outside of the categories?

    Are you in a position to install Query Monitor plugin and then see what query is being generated?

    Thread Starter JelStein

    (@jelstein)

    I expect output based on the single cat_id which I supply. However nothing comes up

    I only get results when I use cat id 6 or cat id 10 All other cat id’s result in nothing on screen.

    I have several other cat id’s which dó have content records.

    [I will look into the oossibility of installing the Query Monitor ]

    Plugin Author Ajay

    (@ajay)

    I just realised one thing as well. Can you also check that your cat ID is the same as the term_taxonomy_id and use that if needed?

    I’m not sure how old your site is, but previously the term_id could have differed from the term_taxonomy_id – the latter is unique.

    Query Monitor should help me see what the exact query is.

    Thread Starter JelStein

    (@jelstein)

    I use the plugin

    1.
    the output of the query monitor for a WORKING QUERY :

    Shortcode is:
    [tptn_list heading=’0′ how_old=35 include_cat_ids=”6″ show_date = ‘1’ limit=’14’ disp_list_count = ‘0’]

    query =

    SELECT DISTINCT wp_top_ten.postnumber, wp_top_ten.cntaccess as sum_count, wp_posts.ID
    FROM wp_top_ten
    INNER JOIN wp_posts
    ON wp_top_ten.postnumber=wp_posts.ID
    WHERE 1=1
    AND wp_top_ten.blog_id = 1
    AND (wp_posts.post_status = ‘publish’
    OR wp_posts.post_status = ‘inherit’)
    AND wp_posts.post_type IN (‘post’, ‘page’, ‘attachment’, ‘event’)
    AND wp_posts.post_date > ‘2020-12-06 17′
    AND wp_posts.ID IN (
    SELECT object_id
    FROM wp_term_relationships
    WHERE term_taxonomy_id IN (6) )
    ORDER BY sum_count DESC
    LIMIT 0, 70

    2. the output of the query monitor for a NON_ WORKING QUERY : (output is nothing)

    Shortcode is:
    [tptn_list heading=’0’ how_old=35 include_cat_ids=”362″ show_date = ‘1’ limit=’14’ disp_list_count = ‘0’]

    query =

    SELECT DISTINCT wp_top_ten.postnumber, wp_top_ten.cntaccess as sum_count, wp_posts.ID
    FROM wp_top_ten
    INNER JOIN wp_posts
    ON wp_top_ten.postnumber=wp_posts.ID
    WHERE 1=1
    AND wp_top_ten.blog_id = 1
    AND (wp_posts.post_status = ‘publish’
    OR wp_posts.post_status = ‘inherit’)
    AND wp_posts.post_type IN (‘post’, ‘page’, ‘attachment’, ‘event’)
    AND wp_posts.post_date > ‘2020-12-06 17’
    AND wp_posts.ID IN (
    SELECT object_id
    FROM wp_term_relationships
    WHERE term_taxonomy_id IN (362) )
    ORDER BY sum_count DESC
    LIMIT 0, 70

    • This reply was modified 3 years, 10 months ago by JelStein.
    Plugin Author Ajay

    (@ajay)

    Thanks for this – the query looks as I expected and I note the difference between the two is the 362 and the 6. My read is that the plugin cannot find any posts that are in taxonomy 362 that were published after 6th December 2020.

    One option to see if the publish-date is the issue is removing the how_old parameter above and seeing if it gives results.

    You might be able to double-check what is the output when you run the sub-query in phpMyAdmin. This would give the post IDs from this category.

    
    SELECT object_id
    FROM wp_term_relationships
    WHERE term_taxonomy_id IN (362)
    

    And, then see if any of these IDs are posts that were published since 6th December 2020. These are also the IDs that should be the postnumber column of wp_top_ten_daily

    Hey, it seems like my custom settings are ignored by CRP. This are the queries that are generared:

    SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.term_taxonomy_id = 58 LIMIT 1

    ————–

    SELECT wp_posts.*, MATCH (wp_posts.post_title) AGAINST (‘? Outdoorknives Magazin ?’) as score
    FROM wp_posts
    WHERE 1=1
    AND ( ( wp_posts.post_date >= ‘1993-09-02 00:00:00’
    AND wp_posts.post_date <= ‘2021-01-17 13:01:03’ ) )
    AND wp_posts.ID NOT IN (89,30,3248,303,20,541,542,539,3282,540,3281,3283,4801,4738,4917,3247,3248,540,3276,30)
    AND ( 0 = 1 )
    AND wp_posts.post_type = ‘page’
    AND ((wp_posts.post_status = ‘publish’
    OR wp_posts.post_status = ‘inherit’))
    AND MATCH (wp_posts.post_title) AGAINST (‘? Outdoorknives Magazin ?’)
    GROUP BY wp_posts.ID
    ORDER BY score DESC
    LIMIT 0, 18

    I normaly match also against the content, that I excluded here to make the query a little bit shorter.

    I added CRP as Gutenberg Blocks. In the Block Settings I added include_cat_ids=58 for this Element.

    All my taxonomies are tags related to pages. I have multiple CRP Elements on each page including the autogenerated CRP.

    It works fine with CRP 2.9.4 and the “Related Posts by Categories and Tags” plugin.

    With CRP 2.9.4 the query looks like this

    SELECT DISTINCT wp_posts.ID, wp_posts.post_date
    FROM wp_posts
    WHERE 1=1
    AND MATCH (post_title,post_content) AGAINST (‘? Outdoorknives Magazin ? Outdoorknives are knives ……………….…’)
    AND wp_posts.post_date < ‘2021-01-17 13:20:48’
    AND wp_posts.post_date >= ‘1993-09-02 13:20:48’
    AND wp_posts.post_status IN (‘publish’,’inherit’)
    AND wp_posts.ID != 30
    AND wp_posts.ID NOT IN (89,30,3248,303,20,541,542,539,3282,540,3281,3283,4801,4738,4917,3247,3248,540,3276)
    AND wp_posts.post_type IN (‘page’)
    AND wp_posts.ID IN (
    SELECT object_id
    FROM wp_term_relationships
    WHERE term_taxonomy_id IN (58) )
    LIMIT 0, 18

    Best
    Cls

    • This reply was modified 3 years, 10 months ago by clsklvr.
    • This reply was modified 3 years, 10 months ago by clsklvr.
    • This reply was modified 3 years, 10 months ago by clsklvr.
    Plugin Author Ajay

    (@ajay)

    @clsklvr

    There is a difference between 2.9.4 which constructed its own query and 3x which uses WP_Query’s for the include_cat_ids.

    I ran some tests on my own install using the Gutenberg block and adding include_cat_ids=25 (in my case I had to use 25) and got this query – note there are a lot more extra conditions because of my tests. But the two main things to point that bring about the include_cat_ids is LEFT JOIN and then the wp_term_relationships.term_taxonomy_id IN (25)

    You should be able to see this when you use 3x

    
    SELECT wp_posts.*, MATCH (wp_posts.post_title) AGAINST ('format') as score
    FROM wp_posts
    LEFT JOIN wp_term_relationships
    ON (wp_posts.ID = wp_term_relationships.object_id)
    WHERE 1=1
    AND ( ( wp_posts.post_date >= '1991-01-25 00:00:00'
    AND wp_posts.post_date <= '2021-01-17 21:33:31' ) )
    AND wp_posts.ID NOT IN (562,903,1333)
    AND ( wp_term_relationships.term_taxonomy_id IN (25)
    AND wp_posts.ID NOT IN (
    SELECT object_id
    FROM wp_term_relationships
    WHERE term_taxonomy_id IN (10) ) )
    AND wp_posts.post_type IN ('post', 'page', 'attachment', 'wz_knowledgebase')
    AND ((wp_posts.post_status = 'publish'
    OR wp_posts.post_status = 'inherit'))
    AND MATCH (wp_posts.post_title) AGAINST ('format')
    GROUP BY wp_posts.ID
    ORDER BY score DESC
    LIMIT 1, 6
    

    I was wondering if CRP may only be included once per page, because I was wondering why all the crp queries e.g. on my startpage looks the same although there is the standard CRP and some custom CRP with specific taxonomies embeded.

    But also on a fresh new page with CRP deactivated for this page, the query of 3x looks like this:

    
    SELECT wp_posts.*, MATCH (wp_posts.post_title,wp_posts.post_content) AGAINST ('Casstr?m ') as score
    FROM wp_posts
    WHERE 1=1
    AND ( ( wp_posts.post_date >= '1993-09-02 00:00:00'
    AND wp_posts.post_date <= '2021-01-17 21:52:25' ) )
    AND wp_posts.ID NOT IN (89,30,3248,303,20,541,542,539,3282,540,3281,3283,4801,4738,4917,3247,3248,540,3276,5005)
    AND ( 0 = 1 )
    AND wp_posts.post_type = 'page'
    AND ((wp_posts.post_status = 'publish'
    OR wp_posts.post_status = 'inherit'))
    AND MATCH (wp_posts.post_title,wp_posts.post_content) AGAINST ('Casstr?m ')
    GROUP BY wp_posts.ID
    ORDER BY score DESC
    LIMIT 0, 6
    

    There is no LEFT JOIN and no wp_term_relationships.term_taxonomy_id IN.

    Do I have to deactivate the “Related Posts by Categories and Tags” plugin maybe? – No does not work either.

    Best
    Cls

    • This reply was modified 3 years, 10 months ago by clsklvr.
    Plugin Author Ajay

    (@ajay)

    Where exactly have you put the include_cat_ids=58?

    Can you also try the shortcode (as a test) and check the query? Also, I assume that you have the caching disabled in the plugin settings page?

    Yes, caching is disabled.

    When the CRP Gutenberg Block is inserted, there is a field in the Block-Settings named “Other attributes”. Here I added “include_cat_ids=58”.

    I also tested it with the shortcode now. It does not work with 3x, only with 2.9.4.
    The query with 3x is

    SELECT wp_posts.*, MATCH (wp_posts.post_title,wp_posts.post_content) AGAINST ('Casstr?m ') as score
    FROM wp_posts
    WHERE 1=1
    AND ( ( wp_posts.post_date >= '1993-09-03 00:00:00'
    AND wp_posts.post_date <= '2021-01-18 22:52:45' ) )
    AND wp_posts.ID NOT IN (89,30,3248,303,20,541,542,539,3282,540,3281,3283,4801,4738,4917,3,3247,3248,540,3276,5005)
    AND ( 0 = 1 )
    AND wp_posts.post_type = 'page'
    AND ((wp_posts.post_status = 'publish'
    OR wp_posts.post_status = 'inherit'))
    AND MATCH (wp_posts.post_title,wp_posts.post_content) AGAINST ('Casstr?m ')
    GROUP BY wp_posts.ID
    ORDER BY score DESC
    LIMIT 0, 6
    Plugin Author Ajay

    (@ajay)

    Thanks @clsklvr

    I have to admit, that I am thoroughly confused as to why this is the case. You’ve definitely put it in the correct place as did I in my testing.
    I tried it on another install and it worked fine as expected.

    Are you able to test this on other posts and see what happens?

    On a very small point, just wanted to clarify that you just used include_cat_ids=58 without any kind of quotes.

    I tested it with quotes and without and also in a new post or page in my case.

    Hm, this is strange. I will also start debugging at the weekend and I tell you, if I find something out.

    Thanks you for your effort so or so!

    Best, Cls

    Hey @ajay,

    I printed in the public function posts_where( $where, $query ) {...} the array $this->query_args and the query string in $where:

    Array ( [include_cat_ids] => 58 [include_post_ids] => 0 [offset] => 0 [postid] => 30 [strict_limit] => [cache_posts] => 0 [cache] => 0 [add_to] => Array ( [page] => page ) [content_filter_priority] => 999 [insert_after_paragraph] => -1 [disable_on_mobile] => 0 [disable_on_amp] => 0 [uninstall_options] => 0 [uninstall_indices] => 0 [uninstall_indices_deactivate] => 0 [show_metabox] => 1 [show_metabox_admins] => 0 [show_credit] => 0 [limit] => 6 [daily_range] => 9999 [ordering] => random [random_order] => [match_content] => 1 [match_content_words] => 0 [post_types] => page [same_post_type] => 0 [same_author] => 0 [exclude_post_ids] => 89,30,3248,303,20,541,542,539,3282,540,3281,3283,4801,4738,4917,3 [exclude_cat_slugs] => [exclude_categories] => [exclude_output_header] => 0 [exclude_on_post_ids] => [exclude_on_post_types] => [html_wrapper_header] => 0 [post_thumb_op] => inline [thumb_size] => crp_thumbnail [thumb_width] => 325 [thumb_height] => 217 [thumb_crop] => 1 [thumb_create_sizes] => 1 [thumb_html] => html [thumb_meta] => post-image [scan_images] => 1 [thumb_default_show] => 1 [thumb_default] => https://hostingkunde.de/wp-content/plugins/contextual-related-posts/default.png [crp_styles] => rounded_thumbs [custom_css] => .related-posts-headline { margin-bottom: 10px !important; } [feed_options_desc] => 0 [limit_feed] => 5 [show_excerpt_feed] => 0 [post_thumb_op_feed] => text_only [thumb_width_feed] => 250 [thumb_height_feed] => 250 [exclude_on_cat_slugs] => [exclude_on_categories] => [same_taxes] => post_tag [match_all] => 0 [no_of_common_terms] => 1 [disable_contextual] => 0 [disable_contextual_cpt] => 1 [crpt_same_taxes] => [crpt_match_all] => 0 [crpt_no_of_taxes] => 1 [crpt_disable_contextual] => 0 [crpt_disable_contextual_cpt] => 1 [is_widget] => [is_shortcode] => [is_manual] => [is_block] => 1 [echo] => 1 [heading] => [extra_class] => add-bottom-40 [more_link_text] => [other_attributes] => include_cat_ids=58 [className] => add-bottom-40 [crp_query] => 1 [suppress_filters] => [ignore_sticky_posts] => 1 [no_found_rows] => 1 [posts_per_page] => 18 [taxonomy_count] => 1 [tax_query] => Array ( [0] => Array ( [taxonomy] => category [field] => term_taxonomy_id [terms] => Array ( [0] => 58 ) ) ) [post_type] => Array ( [0] => page ) [date_query] => Array ( [0] => Array ( [after] => 1993-09-06 [before] => 2021-01-21 17:47:27 [inclusive] => 1 ) ) [post_status] => Array ( [0] => publish [1] => inherit ) [post__not_in] => Array ( [0] => 89 [1] => 30 [2] => 3248 [3] => 303 [4] => 20 [5] => 541 [6] => 542 [7] => 539 [8] => 3282 [9] => 540 [10] => 3281 [11] => 3283 [12] => 4801 [13] => 4738 [14] => 4917 [15] => 3 [16] => 3247 [17] => 3248 [18] => 540 [19] => 3276 [20] => 30 ) )

    AND ( ( wp_posts.post_date >= '1993-09-06 00:00:00' AND wp_posts.post_date <= '2021-01-21 17:47:27' ) ) AND wp_posts.ID NOT IN (89,30,3248,303,20,541,542,539,3282,540,3281,3283,4801,4738,4917,3,3247,3248,540,3276,30) AND ( 0 = 1 ) AND wp_posts.post_type = 'page' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'inherit')) AND MATCH (wp_posts.post_title,wp_posts.post_content) AGAINST ('…')

    I see the term id 58 in the array, but not in the query string. apply_filters is a WordPress function as far as I can see. Is the array structure valid in this case?

    Best
    Cls

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘SHORTCODE – include_cat_IDs works incorrect’ is closed to new replies.