How to organize functions.php content

As @Tom J Nowell says, don’t nest functions. Just write them normally: function my_theme_prefix_setup() { // Add theme support etc. } add_action( ‘after_setup_theme’, ‘my_theme_prefix_setup’ ); function my_theme_prefix_init() { // Register a post type } add_action( ‘init’, ‘my_theme_prefix_init’ ); Or using a class: class my_theme { function __construct() { add_action( ‘after_setup_theme’, array( $this, ‘setup’ ) ); … Read more

get_post orderby not working in plugin

You don’t get any ordering, because you are making multiple get_posts() calls and only retrieve a single post in each of them. You cannot order a single post. 🙂 You need to get rid of outermost loop and just pass a set of IDs (that would be your $instance[‘data’]) to retrieve via single get_posts() call.

Why my query does not run with prepare

That is not how $wpdb->prepare works. You feed prepare a string with sprintf-like placeholders, and the appropriate replacement values. Placeholders The query parameter for prepare accepts sprintf()-like placeholders. The %s (string), %d (integer) and %f (float) formats are supported. (The %s and %d placeholders have been available since the function was added to core in … Read more

how to hide or disable some part in specify page

You want to “reverse” your logic, in a sense. You need “not (home or front)”, not “not home and not front”. For example: // var_dump(is_home(),is_front_page(),(is_home() || is_front_page()),!(is_home() || is_front_page())); // debug if ( !(is_home() || is_front_page()) ) { echo “Hello World”; } else { echo “Else World”; } An easier, more readable way to write … Read more

Trying to make a simple wordpress plugin, having difficulties understanding how to make it?

There are two issues with what your form is currently trying to do: action=”page-rebrander.php” is meaningless to WP (if you actually do have such custom file — you shouldn’t). In WP mechanics you should be typically submitting form to the page itself, options.php (for Settings API), or admin-post.php (for more generic forms). You are trying … Read more

same user role or copy the user role to be same as the other role

Contributor has the following capabilities delete_posts edit_posts read You can create the “Seller” role to have same capabilities as Contributor add_role( ‘seller’, __( ‘Seller’ ), array( ‘read’ => true, ‘edit_posts’ => true, ‘delete_posts’ => true, ) ); Warning from codex NB: This setting is saved to the database (in table wp_options, field wp_user_roles), so it … Read more

php return username of currently viewed author profile

On an author archive page (assuming the plugin uses the core archives) get_queried_object() will return the WP_User object for the author. Something like: $author = get_queried_object(); if (is_a($author, ‘WP_User’)) { var_dump($author->data); } You should see the login, nicename, and display name in there. Use what you need.

Make post title active

Your current code relies on time travel to work: $IDOutsideLoop = $post->ID; global $post; Specifically the first line is peering into the future, how can it know what $post->ID is if it’s undeclared? The fix is global $post;, but when the computer gets to that line, it’s too late global $post; $IDOutsideLoop = $post->ID; If … Read more