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

    (@bcworkz)

    You cannot arbitrarily assign an ID of your choosing as the actual post ID, the database system does this on its own. In any case, they must be unique across the entire system. One way to implement this is to maintain your own numbering system using postmeta just as the linked article has done, except you query by category instead of all posts. When a post is published, script will automatically assign the next available number for that particular category.

    When a category query is done, instead of ordering by date, order by the postmeta field containing the sequence number. Likewise when querying for an individual post, instead of query by ID, you could query by category and sequence number.

    In order to get permalinks to work with this, use the Rewrite API so the permalink form is recognized by the request parser so it knows to query by category and sequence number instead of the default behavior.

    Thread Starter th90

    (@th90)

    Thanks for your answer bcworks.
    Can you give me an example based on what you said?
    i did a change in this code and queried specific category with query_posts.
    but if i want to do this for all categories what i must do?
    tnx.

    Thread Starter th90

    (@th90)

    Hi again.
    I did changes to give id for posts of each category. ( if you need code tell me.)
    now, what i want is only changing the permalinks of posts.
    pleassssssssssse help.

    Moderator bcworkz

    (@bcworkz)

    As mentioned, you need to use the Rewrite API. There are two parts to this. The first is to get the permalinks shown with the post to have the correct structure. Use add_rewrite_tag() to define tags which you can use in defining your permalink style in the admin settings section, or do so dynamically with the API. This gets the various URL fragments assigned to query variables for any post request as well as structuring the permalinks shown for the post.

    The second part is getting the query parser to know how to use these query variables to formulate an SQL query that will find and return the correct post. Unfortunately, I’m unsure of the best approach for this. Left to my own devices, I would use one or more of the numerous “posts_*” filters initiated by the WP_Query::get_posts() method. The relative source code is in wp-includes/query.php around line 2600.

    You callback is passed the relative query text as well as the current query object. You can get the required query variables from the query object and then modify the query text as required before returning it.

    I’m sure this use of filters will work, but there may very well be a better way that I’m unaware of.

    Thread Starter th90

    (@th90)

    I don’t know how to add rewrite rules and rewrite tags .
    i read some examples but they were different methods.
    finally i did not understand what exactly i need to make a custom pretty link.

    Moderator bcworkz

    (@bcworkz)

    I’m sorry, I cannot help you with the actual code. I struggle with the Rewrite API as well. What is required depends on how you want the permalink to appear. You can also alter permalinks by filtering ‘the_permalink’. If you change the link with a filter, the link will 404 unless you also alter how the permalink is parsed.

    Sorry I can’t help more, best of luck to you.

    Thread Starter th90

    (@th90)

    Thank you very much bcworks.
    you helped me a lot around the problem.
    Know i am searching for a code as an example to rewriting existing wordpress permalinks and …

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Numbering posts based on each category’ is closed to new replies.