Jan Beck
  • Member for 9 years, 5 months
  • Last seen more than 5 years ago
How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?
19 votes

I'd like to improve Robs answer by utilizing the WP core functions download_url and media_handle_sideload <?php /** * Downloads an image from the specified URL and attaches it to a post as a post ...

View answer
Remove slug from custom post type post URLs
16 votes

I tried to figure this out not long ago and the short answer from what I know is no. Not from within the rewrite argument at least. The long explanation becomes apparent if you look at the actual ...

View answer
What SQL Query to do a simple find and replace
9 votes

For this I use WP-CLI because I find it the easiest and it takes care of serialized data. wp search-replace 'http://example.dev' 'http://example.com' --skip-columns=guid There is also an option that ...

View answer
Remove slug from custom post type post URLs
8 votes

In response to my previous answer: you could of course set the rewrite parameter to false when registering a new post type and handle the rewrite rules yourself like so <?php function ...

View answer
Generate dormant hook references
6 votes

Sounds like WP Parser does what you are looking for. It is used to generate the official developer reference. It lists parameters, @since tags and references to the source. It works with all WordPress ...

View answer
How to execute SQL SELECT query and see the results?
6 votes

Have a look at the $wpdb class, it does exactly what you want: $myrows = $wpdb->get_results( "SELECT id, name FROM mytable" ); Try to avoid SQL queries for basic operations though. WordPress ...

View answer
Menus like a CMS
4 votes

3 ideas: Create the empty parent pages and use a redirect plugin to redirect all requests from these pages to the children. Inside the menu options page insert a custom link and link to the desired ...

View answer
Is it possible to change the template_directory?
Accepted answer
3 votes

You can filter template_directory_uri: <?php add_filter( 'template_directory_uri', function( $template_dir_uri ){ return str_replace( 'http://example.com', 'https://cdn.example.com', $...

View answer
Getting the image title/alt attribute from the gallery shortcode
Accepted answer
3 votes

A little background: WP stores the attachments in the same database table as posts. Therefore the table rows correspond to the fields of the media edit modal: get_post_gallery_images will return you ...

View answer
Add htmlentities and/or shortcode into data-attributes
2 votes

the_field echoes the output while htmlentities() expects the value to be returned. Try get_field instead: data-img="<?php echo htmlentities(get_field('portfolio_galleries')); ?>" UPDATE: ...

View answer
Redirect within wordpress template/plugin
2 votes

I think you should take a step back and clarify what you are actually trying to do. Usually with WordPress there is no need to throw around with crazy redirects, virtual pages and file includes. ...

View answer
How can I show many posts an author has per week?
Accepted answer
1 votes

Have a look on the date_query parameter that has been added to WP 3.7 WP_Query#Date_Parameters and the author parameter. Combine the two parameters as you need them to query all posts an author ...

View answer
Admin search ACF relationship
Accepted answer
1 votes

Here is a code snippet that will do what you described: add_action( 'pre_get_posts', 'wpsx_185734_acf_search_relationship' ); function wpsx_185734_acf_search_relationship( $q ) { $screen = ...

View answer
Plugin development: how to create a form and get custom data?
1 votes

The details of processing form data is specific to PHP therefore I will not go into it. The WordPress-specific part is that you want your code to be run on the 'init' event in order to have access to ...

View answer
Custom field value based on other custom field values
1 votes

I recommend you look into the get_{$meta_type}_metadata filter. This is a basic hook setup to return a dynamic post meta value: <?php add_filter( "get_post_metadata", function( $points, $post_id, $...

View answer
Why does WP not use relative links when linking pages?
1 votes

Your question seems to have been already answered by a user here: https://stackoverflow.com/a/18516783/844732 However it sounds like your problem would be solved by using this plugin: Relative ...

View answer
Check if page parent has certain template
Accepted answer
1 votes

This question has been answered on Stack Overflow before: https://stackoverflow.com/a/14626254/844732 add_action( 'admin_head', 'check_page_template' ); function check_page_template() { global $...

View answer
How to save media files under "http://example.com/custom_folder" for a specific page
1 votes

The filter you'd want to use is upload_dir. Check for the post_id key in the $_REQUEST super global array to be equal to the page ID you want to limit this for. Then change the uploads directory ...

View answer
Wordpress multisite with subdomain and directory simultaneously
1 votes

It can be done, I'm actually using it for my private multisite installation. Install WP multisite and set it up in "subdirectory-mode" Install and setup the Domain Mapping plugin by WPMU Create a ...

View answer
Best way to organize data in this scenario
Accepted answer
1 votes

I vote for having two separate pages since this gives you all the power of permalinks that go directly to a specific video. That's much better for you and your visitors since the content can be more ...

View answer
Does WordPress refer to any files outside of the main install folder (and database)?
Accepted answer
1 votes

The short answer is no, WordPress does not refer to any files outside of the main install folder. When WordPress loads (via /wp-load.php), it sets the constant ABSPATH to the current directory path ...

View answer
Hide Administrators From User List except current user (administrator)
1 votes

Quoting from the WordPress VIP Development Best Practices: Remember that the database is not a tool box. Although you might be able to perform a lot of work on the database side, your code will ...

View answer
How to show/hide a meta box using categories, with a different post type
1 votes

Instead of if (is_admin()) add_action('admin_menu', 'add_custom_box'); use add_action('add_meta_boxes', 'add_custom_box'); The 'add_meta_boxes' hook is the correct one to add meta boxes. Other ...

View answer
Prohibit saving a post without providing a title
Accepted answer
1 votes

Perhaps these plugins will help you: Mandatory fields This plugin is responsible for making certain fields mandatory before publishing any post in wordpress. Force Post Title This is simple plugin ...

View answer
Include only a domain path in multisite Network
1 votes

Not exactly the answer you might hope for but is using a subdomain an option for you? www.mysite.com - your non WordPress installation blog.mysite.com - WordPress here Subdomains give you even more ...

View answer
Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
1 votes

I can not come up with any reason why you wouldn't want to query the database 12 times if what you need is 12 individual sets of posts except when you are running a site like CNN or NYT where big ...

View answer
Multiple social buttons with a fast loading?
Accepted answer
1 votes

There is a solution that came up recently that is growingly popular especially in the German speaking part of the net called the two-click-method. It loads the buttons only after the user has clicked ...

View answer
forming WP_Query for posts of all post types but from specific categories
1 votes

According to the codex category_name only takes one string value. category_in accepts an array of category IDs: <?php $args = array( 'category__in' = array(1,4,6,8), // use IDs 'post_type'=> ...

View answer
List total number of users that are authors
1 votes

echo count( get_users( array( 'role' => 'author' ) ) )

View answer
Displaying custom taxonomy menu in custom post type archive
1 votes

Displaying two different menus base on the archive is no problem using is_post_type_archive() What you are looking for is essentially the link to an term archive that only contains posts of a certain ...

View answer