All Questions

Filter by
Sorted by
Tagged with
457 votes
7 answers
191k views

When should you use WP_Query vs query_posts() vs get_posts()?

It seems like half the tutorials in the Codex and around the blogosphere use query_posts() and half use WP_Query. They all do similar things, so when should I use one over the others?
Dan Gayle's user avatar
  • 6,066
179 votes
5 answers
197k views

When to use WP_query(), query_posts() and pre_get_posts

I read @nacin's You don't know Query yesterday and was sent down a bit of a querying rabbit hole. Before yesterday, I was (wrongly) using query_posts() for all my querying needs. Now I'm a little bit ...
saltcod's user avatar
  • 2,098
144 votes
5 answers
134k views

How to fix pagination for custom loops?

I have added a custom/secondary query to a template file/custom page template; how can I make WordPress use my custom query for pagination, instead of using the main query loop's pagination? Addendum ...
Chip Bennett's user avatar
  • 54.8k
24 votes
1 answer
2k views

Where do I get "Bug Information" to add to a question?

I have exactly the same issue as this closed question and want to resolve it. In the comment section it asks the OP to add "Bug Information". Where do I get bug information from so I can add it to ...
stephenmyall's user avatar
22 votes
1 answer
8k views

Some doubts about how the main query and the custom query works in this custom theme?

I am pretty new in WordPress theme development and I'm not so into PHP (I came from Java and C#) and have the following situation in this custom theme As you can see in the homepage I first show a ...
AndreaNobili's user avatar
99 votes
7 answers
18k views

Where to put my code: plugin or functions.php?

Is there an easy to understand scheme to decide what kind of code belongs to a plugin or the theme’s functions.php? There are many cases and many debates about that topic, mostly because there are ...
fuxia's user avatar
  • 106k
36 votes
4 answers
9k views

Where do I put the code snippets I found here or somewhere else on the web?

Many posts here or somewhere else contain code, but they do not say where to put it. Example: I have found this post: How do I turn off 301 redirecting posts (not canonical)? I'm a newbie with PHP. ...
Carl's user avatar
  • 361
63 votes
4 answers
73k views

How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name

I've been combing this site and google for the answer and I've come up completely empty. Basically I want to do exactly what this post asks, but I need a hierarchical taxonomy. The answer given in ...
Jeff's user avatar
  • 2,515
43 votes
5 answers
33k views

Pagination not working with custom loop

I've got a custom loop that I'm using to display some Real Estate listings that will be available within 60 days. I'm calling it with the following function: <?php $sixtydays = date('Y/m/d', ...
nurain's user avatar
  • 557
59 votes
1 answer
22k views

A tool to analyze rewrite rules? [closed]

Is there a good tool to analyze my rewrite rules? I always get confused with the regexes and the parameter replacements. I have created something myself and will post it here so others can use it, ...
Jan Fabry's user avatar
  • 30.4k
346 votes
108 answers
167k views

Best collection of code for your 'functions.php' file [closed]

As with many others who are now viewing this post, I have been reading various blogs, forums, and discussion groups to learn and improve my WordPress skills. Over the past 12 months I have been on a ...
111 votes
4 answers
111k views

Menu items description? Custom Walker for wp_nav_menu()

Normal Wordpress Menu looks like: Home | Blog | About us | Contact But I've seen many pages with descriptions under these links: Home Page | Our Blogs | About us | Contact ...
Wordpressor's user avatar
  • 5,011
49 votes
1 answer
75k views

Permalinks: custom post type -> custom taxonomy -> post

I am having trouble working with WordPress rewrite rules, and could use some help. I have a custom post type called _shows_. All shows have a single custom taxonomy category _show-category_. A ...
Paul T's user avatar
  • 667
214 votes
27 answers
62k views

How to: Easily Move a WordPress Install from Development to Production?

I do development on one box and use a second for production. Right now I just dump the database and then do a find a replace for the URL changes; then copy over the files and import the new SQL. Are ...
Ryan Gibbons's user avatar
  • 3,057
54 votes
3 answers
49k views

Is There a Difference Between Taxonomies and Categories?

I've been reading the codex for WordPress closely and am confused about the vague definitions between what a Taxonomy is and what a Category is. For that matter, term is also a word that is used in ...
gate_engineer's user avatar
38 votes
3 answers
53k views

$ not defined using jQuery in WordPress

I know that jQuery is loaded, because I can switch out the $ for 'jQuery' and everything behaves as expected, but this will be a messy script if I can't fix this This script: jQuery(document).ready(...
Mild Fuzz's user avatar
  • 4,160
61 votes
13 answers
85k views

Using wp_query is it possible to orderby taxonomy?

My question is simple, I'm using WP_Query to retrieve some custom type posts filtering by a taxonomy using tax_query. Now my problem is I would like to orderby the taxonomy, but from documentation ...
yeope's user avatar
  • 777
66 votes
3 answers
132k views

Allow HTML in excerpt

Here is my excerpt code. // Generate custom excerpt length function wpbx_excerpt_length($length) { return 300; } add_filter('excerpt_length', 'wpbx_excerpt_length'); How do I allow html like <...
user32447's user avatar
  • 835
66 votes
5 answers
22k views

Custom post types, taxonomies, and permalinks

This is driving me nuts and I'm sure it's simple but nothing I search for comes up with a simple structure (everything is very complex). I have a custom post type product_listing and a custom ...
RodeoRamsey's user avatar
  • 1,707
51 votes
1 answer
9k views

What's the preferred method of writing AJAX-enabled plugins?

I'm wondering what the preferred method is for dealing with AJAX calls. Should one use the same plugin php file to process the POST or a separate one? Which is cleaner or safer?
James's user avatar
  • 625
108 votes
2 answers
60k views

Uninstall, Activate, Deactivate a plugin: typical features & how-to

I'm making a WordPress plugin. What are typical things I should include in the uninstall feature? For example, should I delete any tables I created in the install function? Do I clean up my option ...
redconservatory's user avatar
95 votes
3 answers
42k views

Between functions.php (theme), widgets, and plugins, which is loaded first?

Customer asks if a specific carousel plugin he uses can be widgetized. That means I should create a widget inside functions.php which calls the plugin's function. That means that the plugin's code has ...
pixeline's user avatar
  • 2,837
70 votes
5 answers
50k views

Is there a flowchart for WordPress loading sequence?

So like WP must load series of files from, index.php -> ... -> wp-header.php -> ... ->functions.php ...and so on upon execution. Also there must be a similar flowchart for functions ...
laggingreflex's user avatar
48 votes
1 answer
13k views

Where is the right place to register/enqueue scripts & styles

I am using WordPress 3.1.4 by now. I am confused with where (which hook) do I use: to register and/or enqueue scripts and styles on front- and back-ends? Questions: Which are right hooks to use? ...
JM at Work's user avatar
  • 2,313
104 votes
4 answers
83k views

How to Protect Uploads, if User is not Logged In?

I use WordPress for a private site where users upload files. I use the "Private WordPress" to prevent access in to the site if the user is not logged in. I would like to do the same to the files ...
chifliiiii's user avatar
  • 2,832
7 votes
2 answers
2k views

Clarification on filters and hooks

I am about to start my first WordPress project and I have the task of moving customized core code that override the core into separate functions/files (this way it'll be easier to maintain when we ...
bigpotato's user avatar
  • 335
67 votes
3 answers
12k views

How to remove a filter that is an object method?

In my functions.php file I would like to remove the below filter, but I'm not sure how to do it since it's in a class. What should remove_filter() look like? add_filter('comments_array',array( $this, '...
Jonas's user avatar
  • 791
49 votes
2 answers
24k views

Create more Meta Boxes as needed

I'd like users to be able to create and remove additional meta box fields as needed. For example, say a music podcast with a variable amount of songs played per episode. The user should be able to ...
Picard102's user avatar
  • 933
24 votes
3 answers
6k views

Modifying WordPress core files

Why? Sometimes an easy fix to altering the behavior of WordPress itself or a plugin could be to alter the files of the plugin or WordPress directly. When coming up with such an idea, the usual ...
user avatar
7 votes
4 answers
2k views

Shortcode outputs at the top of the_content

The shortcode produced by this function - a list of all sites in a multisite - outputs above the content in the loop, no matter where it is placed in the editor. I've looked at the other related ...
markratledge's user avatar
  • 8,695
106 votes
6 answers
165k views

Using wpdb to connect to a separate database

I want to connect wpdb to another database. How do I create the instance and pass it the database name/username/password? Thanks
Wadih M.'s user avatar
  • 2,838
13 votes
3 answers
6k views

Custom post meta field effect on the performance on the post

I have the posts which have many custom defined meta fields. On posts I am calling them on requirement using get_post_meta. Means for 10 meta fields I am using it 10 times. Am I doing it right? ...
Akhilesh's user avatar
  • 235
150 votes
13 answers
57k views

Hide the fact a site is using WordPress?

I have a website for which we are trying to be discreet about the fact that we are using WordPress. What steps can we take to make it less obvious? EDIT- Important security note: Please understand ...
Casebash's user avatar
  • 1,645
76 votes
8 answers
66k views

remove_action or remove_filter with external classes?

In a situation where a plugin has encapsulated its methods within a class and then registered a filter or action against one of those methods, how do you remove the action or the filter if you no ...
Tom Auger's user avatar
  • 7,006
33 votes
6 answers
15k views

Turn a URL into an Attachment / Post ID

Is there any way I can take a URL of an image and find the attachment or post id of that image in the database? Here is the situation: I'm in a loop going over all the 'img' tags that are surrounded ...
Ankur's user avatar
  • 433
71 votes
4 answers
38k views

Programmatically add widgets to sidebars

I would like to programmatically add widgets to my two sidebars that I've got. I couldn't find any official way of doing it? I started looking in the database. I've found that it's the '...
Marlun's user avatar
  • 821
40 votes
1 answer
25k views

Settings API with arrays example

I'm using the Wrox WordPress plugin development book as a primary reference for getting started with a new plugin and I understand all settings can be saved as 1 array but the book does't give an ...
Bjorn's user avatar
  • 702
142 votes
9 answers
23k views

Tips for using WordPress as a CMS? [closed]

I want to use WordPress as a CMS for a reasonably basic site rather than a blog. I have several pages and at the moment, I don't intend to have a "news" page. While there are ways to make this work, ...
84 votes
10 answers
66k views

Enqueue Scripts / Styles when shortcode is present

What is the idea way to register/enqueue scripts and/or styles for use in plugins? I recently made a plugin simple plugin to add the user avatar/gravatar with a shortcode. I have different style ...
Bryan Willis's user avatar
  • 4,349
55 votes
2 answers
24k views

Ajax takes 10x as long as it should/could

I have just hit my first serious issue with WordPress and for someone that enjoys Ajax this is a biggy. I have an Ajax request that is taking 1.5 seconds to complete while using the Ajax API. If I ...
Mike's user avatar
  • 813
7 votes
8 answers
58k views

Get all categories and posts in those categories

I am looking for a solution that allows me to print the following: Cat 1 Cat 2 Cat 3 Post 1 Post 1 Post 1 Post 2 Post 2 Post 2 Post 3 Post ...
Ben's user avatar
  • 233
110 votes
12 answers
17k views

Verifying that I have fully removed a WordPress hack?

My for-fun WordPress blog at http://fakeplasticrock.com (running WordPress 3.1.1) got hacked -- it was showing an <iframe> on every page like so: <iframe src="http://evilsite.com/go/1">&...
Jeff Atwood's user avatar
  • 2,095
75 votes
18 answers
7k views

WPSE Plugin Repository: The plugins that came out of WP-Answers

Link your WPSE-Plugins If you answered a question and made a plugin out of your code, than this is your place to share it. The Idea: An old comment from @MikeSchinkel during the beta phase where he ...
73 votes
4 answers
33k views

What is the preferred way to add custom javascript files to the site?

I've already added my scripts, but I wanted to know the preferred way. I just put a <script> tag directly in the header.php of my template. Is there a preferred method of inserting external or ...
naugtur's user avatar
  • 1,153
20 votes
2 answers
23k views

Shortcode always displaying at the top of the page

I'm using a shortcode to pull in different loops via the loops-name.php. For some reason it is always at the top of the page. I googled it and using echo instead of return causes that problem but with ...
john joe's user avatar
  • 205
135 votes
17 answers
105k views

Adding a Taxonomy Filter to Admin List for a Custom Post Type?

I have created a Custom Post Type called 'listing' and added a Custom Taxonomy called 'businesses'. I would like to add a dropdown list of Businesses to the admin list for the Listings. Here is what ...
Taras Mankovski's user avatar
113 votes
11 answers
47k views

Display a portion/ branch of the menu tree using wp_nav_menu()

I have a menu defined in WP Admin that looks like this: I want to be able to display all the child links on the sidebar whenever I am at a parent page. For example, if the user is on my "About Us" ...
jessegavin's user avatar
  • 3,416
71 votes
7 answers
108k views

What is the correct way to use WordPress functions outside WordPress files?

I read about 2 methods for initializing WordPress function outside of WordPress files so We can use these functions on any page or website outside the WordPress blog. Which one of these 2 methods is ...
alhoseany's user avatar
  • 1,201
50 votes
14 answers
78k views

meta_query with meta values as serialize arrays

I'm working on a project in which I'm creating a custom post type and custom data entered via meta boxes associated with my custom post type. For whatever reason I decided to code the meta boxes in ...
tollmanz's user avatar
  • 5,430
43 votes
9 answers
119k views

Add category base to URL in custom post type/taxonomy

I am building an LMS type system in WordPress, controlled by Custom Post types. The post type is called Lessons (with a slug of courses) and it has one custom taxonomy (category) called courses. The ...
Zach Russell's user avatar
  • 1,043

15 30 50 per page
1
2 3 4 5
190