aifrim
  • Member for 7 years, 5 months
  • Last seen more than a month ago
Deactivate plugin for a specific user group
Accepted answer
6 votes

I think the answer to this Disable plugin / plugin action via theme is good for base knowledge on how to disable plugins from code. Adapting that knowledge to your needs will leave us with this: ...

View answer
$wpdb - do you have to use foreach even if there will always only be one result?
Accepted answer
5 votes

Read the Codex: The get_var function returns a single variable from the database. Though only one variable is returned, the entire result of the query is cached for later use. Returns NULL if no ...

View answer
Restrict custom post type view by user role
5 votes

Every role has capabilities. Here is a simple contributor to our endeavor: (he just writes and edits) add_role('contributor', 'Contributor', array( 'read' => true, 'edit_posts' => true,...

View answer
How to include plugin without activation?
Accepted answer
4 votes

WP_PLUGIN_DIR.'/pluginName/' will give you the absolute path to the directory of the plugin. EDIT After comment Plugins are plugins, theme files are theme files. Lets not confuse the two. You cannot ...

View answer
get post id in while loops outputting page id
3 votes

Dont use query_posts or WP_Query if you need it in the main loop. Dont ever use query_posts anyway. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $current_id =...

View answer
Overwrite or Replace code in WP_Footer
Accepted answer
2 votes

Since you ruled out remove_action there is only one way you can do it. And you've guessed it: preg_repalce, substr mixture but with a little help and PHP DOM add_action('wp_footer', '...

View answer
Single Loop With Dual Content Area
2 votes

Lets first start with a bit of knowledge-base: the_content is this /** * Display the post content. * * @since 0.71 * * @param string $more_link_text Optional. Content for when there is more text....

View answer
register_activation_hook on multisite
Accepted answer
2 votes

And the answer is that a datetime cant have the CURRENT_TIMESTAMP default value since MySQL 5.6.5 so I changed modify_date from datetime to timestamp and all is good.

View answer
Wordpress action and filter hooks runs asynchronously?
1 votes

Whatever the action/filter you hooked your code into they (the callbacks) DO NOT run asynchronously. PHP is not Javascript/Java/C# or any other programming language & compiler/interpreter that ...

View answer
wrong template for page of archive
Accepted answer
1 votes

Because WordPress redirected to index.php when it should have loaded archive.php or archive-cpt.php I made a workaround like so: add_rewrite_rule( $cpt_name . '/page/?([0-9]{1,})?$', 'index....

View answer
post editor changes & to &amp;
1 votes

I dont know what you are doing with your shortcode but it is good practice to serialize and parse data so that it displays beautifully. Since you need to look for & and not for &amp; just use ...

View answer
Where to use $post global variable?
1 votes

Within the loop you have functions like: the_ID() or get_the_ID() that return $post->ID the_title() or get_the_title() that return $post->post_title the_content() or get_the_content() that ...

View answer
Adding a badge to new blog post titles
1 votes

You want to edit the title, and not the content. Check this for filters you want to use. If you want to edit your title you should add_filter to it and modify it(the_title). Like so: add_filter('...

View answer
How to check if new posts have been published since page load?
1 votes

First you need to give him the date to send when the ticks comes: // Hook into the heartbeat-send and give him the milliseconds timestamp since epoch $(document).on('heartbeat-send', function(e, data)...

View answer
pre_get_posts post_meta event
0 votes

Thanks to Marcin I managed to solve all the problems. function o_pre_get_posts_events($query) { if (is_post_type_archive("post")) { // I need this for all my other cpts, but not for post ...

View answer
Custom post type paging 404 error
0 votes

I had the same problem and I found the answer today. I've added a rewrite rule for a workaround. check my answer for this question: wrong template for page of archive

View answer
Add an Exclusive or featured tag line to article titles
0 votes

get_the_time('U') returns $string. You cannot subtract a string from an integer function new_badge(){ if ( (time() - strtotime ( get_the_time( 'U' ) ) ) <= (3*86400)) { echo '<div ...

View answer
Unable to upload specific .zip file type via frontend in WordPress 4.0
0 votes

You need need to update the allowed mime-types that WordPress has in its settings. For zip/rar files: function my_modify_mimes( $mimes ) { $mimes['zip'] = 'application/zip'; $mimes['rar'] = ...

View answer
Register a widget area when a theme option has been saved?
0 votes

In functions.php write this code function my_optionally_widgets() { $option = get_options('wantwidget'); if($option == 'yes') { register_widget('mywidget'); /* add other ...

View answer
How can I group posts by date on frontpage?
0 votes

You test when the date changes and only show it once, right when it changed for the first time. <?php $date = 0; $newDate = true; if (have_posts()) : while (have_posts()) : the_post(); ...

View answer
Option doesn't save
0 votes

An option is a meta information saved in the database as a string. An array is a memory specific variable that has its own characteristics. But to every problem there is a workaround: $myoption = ...

View answer
Custom taxonomy - custom sortable column
0 votes

A custom field is a custom post meta data made by the user or a theme/plugin, in this case that custom field is named yesno. To add a column for it to posts or custom post types (myposttype): ...

View answer
Exclude Taxonomy Terms from Template Via Back End?
0 votes

Hy, From what I understand you want a filter to display posts that belong to a specific list of terms. As default you display all posts making all terms enabled. In order to disable a term from being ...

View answer
Change "en-US" to "en"
Accepted answer
-1 votes

If you want to get the language of the browser do so: $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); If you want to redirect to ?lang=en: header("location: {$_SERVER['REQUEST_URI']}?lang={$...

View answer
Integrating a custom post type into a page hierarchy
-1 votes

<?php the_post(); // $postType holds all the information of the post type of the current post you are viewing $postType = get_post_type_object(get_post_type()); // $postSlug is the slug you ...

View answer
User Defined order on get_categories?
-2 votes

Here is a workaround: Create a menu named Category Menu register_nav_menu( 'category-menu', "Category Menu ); Now your client can configure the menu as he pleases. All you have to do is paste the ...

View answer
Pagination for blog posts reloading same page
-2 votes

Why don't you force the pagination by adding the following code like so: <div id="main-content"> <div class="container"> <section id="content" class="blog"> ...

View answer