• Resolved Willem 2

    (@willem-2)


    Is there a possibility to give a primary category its own weight? It is possible for categories but I want it also for the primary category.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mikko Saari

    (@msaari)

    What do you mean exactly? Do you want to give more weight to the post if the search term matches the post’s primary category? And which primary category do you mean? Are you using Yoast SEO for the primary category functionality?

    Thread Starter Willem 2

    (@willem-2)

    Thanks Mikko for your reaction,

    Yes, I want to give a post more weight when the search term matches the posts primary category. This is the primary category which I have given to a post with Yoast SEO.

    Plugin Author Mikko Saari

    (@msaari)

    Looks like you can use the yoast_get_primary_term( $taxonomy, $post_id ) function to get the name of the primary term for the post. You could use that in a weighting function to adjust the post weight if the search term matches the primary term name.

    However, since yoast_get_primary_term() uses get_post() to get the post and get_term() to get the primary term, that’s potentially expensive and on a large site may lead to hundreds of extra database calls per search.

    The best approach would be to construct a single database call that gets the (post ID, primary term name) pairs from the database, run that first and store the results in an array to use later. That would be more efficient. I’m not sure how Yoast SEO stores the data. If it’s still using the _yoast_wpseo_primary_category custom field, building the MySQL query to get the post IDs and term names shouldn’t be difficult.

    Thread Starter Willem 2

    (@willem-2)

    Hi Mikko, thanks for your replay but it is too difficult for me. I tried to understand it but I came to the conclusion that I am too old for it (age 72). I can only put a code in the functions.php of my Child theme or an existing code in the phpcode snippets plugin.

    Plugin Author Mikko Saari

    (@msaari)

    This is a complicated enough problem to do well that I can’t simply provide a snippet you can add to your functions.php. You could get a WP developer to do this for you, but I don’t think the benefit would be worth the cost.

    Thread Starter Willem 2

    (@willem-2)

    Hi Mikko, Thank you for your answer. I Will close this threat.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Primary category weight’ is closed to new replies.