Tag Info

Hot answers tagged

2

$wpdb->get_results() returns an index array of row objects, but it looks like you're expecting $exists to contain the actual value of the used column. you probably want $wpdb->get_var(): http://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Variable


2

The wp_rand function mixes up the randomization of random numbers with various means, and in between runs it stores the random seed so as to keep the shuffling going every run. The random_seed transient is where it stores that.


1

Just to clarify the get_var() method of $wpdb does work just fine in this context: global $wpdb; $helloworld_id = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_name = 'hello-world'"); echo $helloworld_id; Actually it is more practical in this context, because a single variable is returned, which is what is actually wanted.


1

Why do your own database queries? Use the WP functions to do it for you. $empid = (int) $_REQUEST['empid']; $name = get_user_meta($empid, 'first_name', true) . ' ' . get_user_meta($empid, 'last_name', true);


1

$wpdb->prepare() is only necessary when trying to insert user input into a SQL query. If it's a "static" SQL query, it's not necessary.


1

Simple, hook on the query filter and structure that "unstructured" sql data. Parsing SQL is annoying but can't be that difficult. Of course some queries are ran before plugins are loaded as you do need to get the list of active plugins and active theme before including their file. And if you need to access a DB which is different from mysql or ignores the ...


1

You will have to define post order in second SQL query too. Try this one. // get years that have posts $years = $wpdb->get_results( "SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY year DESC" ); foreach ( $years as $year ) { // get posts for each year $posts_this_year = ...


1

Have you tried $wpdb->replace. According to WP Codex: Replace a row in a table if it exists or insert a new row in a table if the row did not already exist. I have tried myself in some plugins and it does the work when trying to avoid unique IDs duplication errors, etc. More info in the codex


1

You would create your own dp.php file in the wp-content directory; if you define $wpdb in there, it will replace WordPress's default $wpdb object. It's not listed on the Pluggable Functions list (not a big surprise, as $wpdb is a class, not a function), but it seems similar in concept. Also, if you haven't read it yet, I'd recommend you peruse the WPDB ...


1

You need to create the file by yourself. This is one of the files that are reffered as "drop-ins". They are not distributed with the wordpress core and their purpose is to extend functionality, in the db.php case to replace the default database "driver" with another one, for example to communicate with a DB which is not MYSQL. A typical structure of the ...


1

As you can guess from version number this code is ancient. So ancient in fact that var keyword is from PHP 4 and is deprecated in PHP 5 (considered synonym of public for backwards compatibility). So inline doc hints it is private because back then there was no actual property visibility in PHP language. So conceptually it probably would have been protected ...


1

This constant is actually never defined in core code at all. You can define it yourself in wp-config.php configuration if you need to, but core doesn't need it defined for normal operation. It only exists for re–configuring into running untypical setup.


1

My SQL knowledge is quite bad, I should admit, so I'm going to use a non SQL way to achieve this. Here is my idea: Use pre_get_posts to alter the query variables before the main query is executed. As all of the query variable has been set by the time pre_get_posts run, you can simply change them as needed, and also, the conditional tags are available, so ...



Only top voted, non community-wiki answers of a minimum length are eligible