Software Engineering in WordPress, PHP, and Backend Development

Author: Tom (Page 368 of 423)

Properly Calculating Page Offset in Custom WordPress Queries

Whenever it comes to writing custom queries in WordPress, pagination always seems to give developers problems (myself included!).

I think this can be chalked up to the next / previous pagination links (so does next mean older, or newer?), paginating single posts as well as archive posts, and then occasionally having to write custom queries that include pagination.

One of the areas that I see most confusing – again for myself as well – is properly calculating page offsets especially when working with the WP_Query offset parameter.

The thing is, I think it can be much more simplified (or, perhaps, demystified?) when visualizing the data that you’re working with, and knowing how to use some of the existing API links.

So here’s what you need to know in order to get pagination working when working with the WP_Query offset, page, and number parameters.

Continue reading

How To Setup Custom Queries For WP_Query Pagination

One of the nicest things about using WP_Query is that it allows you to completely customize the data that you’re bringing back to the front end.

For those of you who are completely unfamiliar with this API, it’s a powerful class that allows you to custom tailor a query against the WordPress database for retrieving information about posts, pages, custom post types, and so on.

If you’re using one of the more common features of WordPress, such as those mentioned above, then it’s relatively easy to get started; however, if you’re doing more complicated work, such as including multiple custom queries in a single view, then there are some challenges that you may discover.

Personally, I’ve been working on a project where I have two custom queries running in a template and I needed to paginate the results. The problem is that using the usual functions for doing this, that is:

Were not working as expected.

Ultimately, it required me passing a little bit more information to the query’s arguments array and to the pagination link functions. Here’s how you can setup WP_Query Pagination to work properly in custom queries.

Continue reading

Three Thoughts on Improving Code Quality in Existing Projects

I’m currently working on a project that I inherited from a previous team in which I’m working on improving the code quality. The details aren’t terribly important, but here’s what you need to know to have enough context for this post:

  • I didn’t design the application, but the client wants to keep the existing design and feature set
  • The budget only allows for improvements agreed upon during the planning phase – nothing more
  • The initial codebase was developed by someone else that opted to do things in a less elegant way

As far as the last point is concerned, “less elegant” could be chalked up to laziness, or it could be chalked up to ignorance.

When possible, I try to believe the best rather than assume the worst, so I’ve opted to go with the fact that the team was under a deadline to ship rather than to build an elegant solution.

That said, I think that all developers have found themselves in this position: We’ve inherited – or contributed – to some codebase, looked around, and said:

I wouldn’t have done it that way.

Often times, the implication is that our way is a better way than the way it’s currently done. In some cases, that’s right, but if developers often think this and another developer wrote said code, where does that lead?

Anyway, this is not the first time I’ve found myself in this position, and it certainly won’t be the last, but it seemed like something worth discussing if for no other reason to share my thoughts on it.

Continue reading

Another WordPress Podcast?

One of my favorite things to do when going on a run or a long drive is to queue up a few podcasts and listen to them. Generally speaking, most of the podcasts that I listen to are directly related to things I’m interested in and/or interested in learning more about.

Then again, isn’t that what everyone listens to?

With that said, I can honestly say that I’m not familiar with a significant number of high quality WordPress podcasts. In fact, the one’s I’m most aware of are published by WPCandy, and Jeff at WPTavern (on which I had to pleasure speaking last year).

I have an idea for another type of WordPress podcast, but I’m wondering if there’s room for it, or if the reason there are so few is because there’s so little interest.

Continue reading

« Older posts Newer posts »

© 2024 Tom McFarlin

Theme by Anders NorenUp ↑